Skip to content

Instantly share code, notes, and snippets.

@optixx
Created June 25, 2009 18:10
Show Gist options
  • Save optixx/136034 to your computer and use it in GitHub Desktop.
Save optixx/136034 to your computer and use it in GitHub Desktop.
###############################################################################
# Prompt
###############################################################################
BLACK="%{%}"
BOLD_BLACK="%{%}"
RED="%{%}"
BOLD_RED="%{%}"
GREEN="%{%}"
BOLD_GREEN="%{%}"
YELLOW="%{%}"
BOLD_YELLOW="%{%}"
BLUE="%{%}"
BOLD_BLUE="%{%}"
MAUVE="%{%}"
BOLD_MAUVE="%{%}"
CYAN="%{%}"
BOLD_CYAN="%{%}"
WHITE="%{%}"
DEFAULT="%{%}"
# set shell title
function title() {
# escape '%' chars in $1, make nonprintables visible
a=${(V)1//\%/\%\%}
# Truncate command, and join lines.
a=$(print -Pn "%40>...>$a" | tr -d "\n")
case $TERM in
screen)
print -Pn "\ek$a:$3\e\\" # screen title (in ^A")
;;
xterm*|rxvt)
print -Pn "\e]2;$2 | $a:$3\a" # plain xterm title
;;
esac
}
function issucceed {
if [ "$1" -eq 0 ]; then
HIST_COLOR="$BOLD_RED"
PREFIX=""
else
HIST_COLOR="$BOLD_BLACK"
PREFIX="[$BOLD_RED${1}$BLACK]"
fi
}
function precmd {
issucceed "$?"
PS1="${PREFIX}[$BOLD_BLUE%n$BLACK@$BOLD_GREEN%m$BLACK]$BOLD_MAUVE%3c $DEFAULT%# "
RPS1="[$HIST_COLOR%!$BLACK]"
test -z $SUDO_USER || PS1="${PREFIX}[$BOLD_RED%n$BLACK@$BOLD_RED%m$BLACK]$BOLD_MAUVE%3c $DEFAULT%# "
title "zsh" "$USER@%m" "%25<...<%~"
}
## preexec is called just before any command line is executed
function preexec() {
title "$1" "$USER@%m" "%25<...<%~"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment