Samstag, 26. Juni 2010

Current git branch in a zsh prompt

I've looked for hours to find a way to just display the current git branch in the prompt of my zsh shell and I've come to this more or less understandable solution which should work with any common VCS available:

autoload -U colors && colors
autoload -Uz vcs_info

zstyle ':vcs_info:*:prompt:*' formats "$VCSPROMPT" "[%b]"

precmd() {
vcs_info 'prompt'

if [ -n vcs_info_msg_0_ ]; then
RPROMPT="${vcs_info_msg_1_}"
else
RPROMPT=""
fi
}

PROMPT=$'%F{green}%~#%f '


The result is that the current working directory is shown on the left side and the name of the branch in braces on the right. I could probably configure it in a way which shows me a lot more information but all I want is a little reminder about the branch I'm currently in.

Keine Kommentare:

Kommentar veröffentlichen