Skip to content

Instantly share code, notes, and snippets.

@dbb
Created May 27, 2012 17:18
Show Gist options
  • Select an option

  • Save dbb/2815146 to your computer and use it in GitHub Desktop.

Select an option

Save dbb/2815146 to your computer and use it in GitHub Desktop.
zsh prompt
# dbbolton's zshrc
## snip all lines not directly related to the prompt
# host symbols
# if [ $TERM == 'rxvt-unicode' ]; then
if [ $HOST == 'ganymed' ]; then
HOST_SYM='♃ '
elif [ $HOST == 'reddevil' ]; then
HOST_SYM='♆ '
elif [ $HOST == 'barrett' ]; then
HOST_SYM='☉'
else
HOST_SYM='%%'
fi
function precmd {
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 1 ))
PR_FILLBAR=""
PR_PWDLEN=""
local promptsize=${#${(%):---(%n@%m:%l)---()--}}
local pwdsize=${#${(%):-%~}}
local filesize=${#${(%):-$FILECOUNT}}
if [[ "$promptsize + $pwdsize" -gt $TERMWIDTH ]]; then
((PR_PWDLEN=$TERMWIDTH - $promptsize))
else
PR_FILLBAR="\${(l.(($TERMWIDTH - ($promptsize + $pwdsize + $filesize + 5)))..${PR_HBAR}.)}"
fi
## git stuff ##
GIT_STAT=''
GIT_BRANCH=''
if [[ -d .git ]]; then
if [[ -z $( git status | grep "nothing to commit" ) ]]; then
GIT_STAT='+'
fi
if [[ -d .git ]]; then
GIT_BRANCH=`git branch | perl -ne 'print if s{\*\s*}{}'`
fi
GIT_PROMPT="${GIT_STAT} ${GIT_BRANCH}"
fi
## dir name
count=$( print $PWD | wc -c )
if [[ $count -lt 30 ]]; then
PR_DIR='%~'
PR_RDIR=''
else
PR_DIR='…/%c'
fi
}
setcolors () {
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE BLACK; do
eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
(( count = $count + 1 ))
done
PR_NO_COLOR="%{$terminfo[sgr0]%}"
}
setcolors
setprompt () {
# box-drawing characters
typeset -A altchar
set -A altchar ${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
PR_HBAR=${altchar[q]:--}
PR_ULCORNER=${altchar[l]:--}
PR_LLCORNER=${altchar[m]:--}
PR_LRCORNER=${altchar[j]:--}
PR_URCORNER=${altchar[k]:--}
setopt prompt_subst
case $TERM in
xterm*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
screen)
PR_TITLEBAR=$'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'
;;
rxvt-unicode*)
PR_TITLEBAR=$'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'
;;
*)
PR_TITLEBAR=$'%n@%m:%~'
;;
esac
if [[ "$TERM" == "screen" ]]; then
PR_STITLE=$'%{\ekzsh\e\\%}'
else
PR_STITLE=''
fi
# Some interesting prompt chars
# ≻ ≽ ≿ ⊃ ⊇ ⋟ ⌘ ▶ ▷ ▸ ▹ ► ▻ ⚡ ❩ ❫ ❭ ❯ ❱ ➔ ➙ ➛ ➜ ➝ ➞ ➟
# ➠ ➡ ➢ ➣ ➤ ➥ ➳ ➵ ➸ ➺ ➻ ➼ ⇋ ⇌ ∫ ∬ ∭ ∴ ∵ ≍
PROMPT_CHAR='≻≻'
if [ $TERM == 'linux' ] ; then
PROMPT='$PR_BLUE%n$PR_WHITE@$PR_RED%m$PR_WHITE:$PR_YELLOW%c$PR_WHITE%%$PR_NO_COLOR '
RPROMPT='tty%l,%?? ${PR_RED}%D{%l:%M:%S %p}${PR_NO_COLOR}'
else
PROMPT='
${PR_BLUE}${HOST_SYM} ${PR_MAGENTA}${PR_DIR} ${PR_RED}${PROMPT_CHAR}${PR_NO_COLOR} '
RPROMPT='${PR_YELLOW}${GIT_PROMPT}${PR_NO_COLOR} '
}
setprompt
@dbb

dbb commented May 27, 2012

Copy link
Copy Markdown
Author

zsh screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment