我希望基于vcs_info变量hook_comstaged在zsh提示符上显示hook_comstaged的两种不同格式。
以下是我的.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
}预期的结果是让vcs的信息(对于git)看起来像:
除非我刚刚做了改变,否则效果很好:
[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)]>%我是不是错过了vcs_info上的内存或钩子?
发布于 2020-01-20 12:40:45
我不是专家,但是你有没有试着把vcs_info放在你的条件之后:
precmd() {
if [[ -n ${tag} ]] ; then
zstyle ':vcs_info:git:*' formats "[%s@%b(%c%m)]"
else
zstyle ':vcs_info:git:*' formats "[%s@%b]"
fi
vcs_info
}发布于 2020-01-20 16:30:11
我的提示符设置为单引号的双引号整数。我不知道为什么,但这解决了我的问题。
https://stackoverflow.com/questions/59820401
复制相似问题