I want to have two different format for displaying vcs_info on my zsh prompt based on the vcs_info variable hook_com[staged]
Here is the important part of my .zshrc
plugins=(git)
autoload -Uz vcs_info
tag=""
zstyle ':vcs_info:git:*' check-for-staged-changes true
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+vi-git-untracked(){
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep ' M ' &> /dev/null ; then
hook_com[staged]+='M'
tag="OK"
else
tag=""
fi
}
precmd() {
vcs_info
if [[ -n ${tag} ]] ; then
zstyle ':vcs_info:git:*' formats "[%s@%b(%c%m)]"
else
zstyle ':vcs_info:git:*' formats "[%s@%b]"
fi
}
The expected result is to have the vcs information (for git) look like:
- [git@master] // No modified files
- [git@master(M)] // Modified files
Which work fine unless I just made the change:
[20/01-10:31]<zmx@bgtian:~/misc[git@master]>% echo "aa" >> README.md
[20/01-10:32]<zmx@bgtian:~/misc[git@master]>% cd . // on this line I should have seen the change.
[20/01-10:32]<zmx@bgtian:~/misc[git@master(M)]>%
Did I miss something with the precmd or the hooks on vcs_info ?