I've got a simple but custom .zshrc that I'd like to populate the prompt with the git branch I'm currently on (when in a git repo). The code below seems to work, but one prompt behind where I'm actually at.
.zshrc:
#Prompt messing
# Load colors for prompt
autoload -U colors && colors
# Load version control information
autoload -Uz vcs_info
precmd() {
vcs_info
if [[ -n ${vcs_info_msg_0_} ]]; then
# allow check for changes
zstyle ':vcs_info:*' check-for-changes true
#sets unstaged string to this
zstyle ':vcs_info:git:*' unstagedstr "!"
#sets staged string to this
zstyle ':vcs_info:git:*' stagedstr "+"
zstyle ':vcs_info:git:*' formats '%K{green}%u%k%K{cyan}%c%k'
BRANCH=$(command git rev-parse --abbrev-ref HEAD)
PS1='%F{magenta}%7>>${BRANCH}%<<%f'
PS1+='${vcs_info_msg_0_} %~; '
else
PS1='%~; '
fi
}
For example:
master ~/code/external-api; cd ..
master ~/code;
~/code;
I would expect the second line there to not have the master in the prompt.
Any help is greatly appreciated!