Skip to content

Instantly share code, notes, and snippets.

@syu-id
Created May 10, 2013 01:38
Show Gist options
  • Save syu-id/5551854 to your computer and use it in GitHub Desktop.
Save syu-id/5551854 to your computer and use it in GitHub Desktop.
A minimalistic Zsh prompt, with a reverse ordered current working directory on the right-hand side, and a vi normal mode indicator.
# load colors
autoload -U colors
colors
PROMPT="%{$fg_bold[white]%}%#%{$reset_color%} "
# RPROMPT vi mode indicator
VI_INDICATOR="%{$fg_bold[blue]%}vi%{$reset_color%}"
revpwd() {
rawpath=$(print -P "%~") # get current working directory
apath=(${(s:/:)rawpath}) # split to array
rpath=(${(Oa)apath}) # reverse the array
revpath=${(j:/:)rpath} # rejoin the reversed array
if [[ $apath[1] != '~' ]]; then # add trailling '/', except for '~'
revpath="$revpath/"
fi
# print RPROMPT formatting
echo "%{$fg[yellow]%}$revpath%{$reset_color%}"
}
# orig of the codes below: http://zshwiki.org/home/zle/vi-mode
precmd() {
RPROMPT="$(revpwd)"
}
zle-keymap-select() {
RPROMPT="$(revpwd)"
[[ $KEYMAP = vicmd ]] && RPROMPT="${VI_INDICATOR} $(revpwd)"
() { return $__prompt_status }
zle reset-prompt
}
zle-line-init() {
typeset -g __prompt_status="$?"
}
zle -N zle-keymap-select
zle -N zle-line-init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment