Created
May 10, 2013 01:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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