我正在尝试修改bart theme,因此它包含git状态信息。我让它工作,但是当我更改目录时它不会更新
我通过启用vcs_info修改了bart主题:
prompt_bart_setup () {
# ...
autoload -Uz vcs_info
# Set vcs_info parameters.
zstyle ':vcs_info:*' enable bzr git hg svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '%F{green}●%f'
zstyle ':vcs_info:*' unstagedstr '%F{yellow}●%f'
zstyle ':vcs_info:*' formats ' - [%b%c%u]'
zstyle ':vcs_info:*' actionformats " - [%b%c%u|%F{cyan}%a%f]"
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b|%F{cyan}%r%f'
zstyle ':vcs_info:git*+set-message:*' hooks git-status
# ...
}
prompt_bart_precmd () {
# ...
vcs_info
# ...
}
并填充RPROMT变量(它也适用于PS1,但我想隔离问题):
prompt_bart_ps1 () {
# ...
RPROMPT="${vcs_info_msg_0_}"
# ...
}
如果我在git repo中创建一个新的终端会话,这是有效的,但是当我更改目录时它不会更新。
我已经看到了使用单引号的建议,但是当我将其更改为:
prompt_bart_ps1 () {
# ...
setopt promptsubst
RPROMPT='${vcs_info_msg_0_}'
# ...
}
提示符字面显示为${vcs_info_msg_0_}
。有什么想法吗?
答案 0 :(得分:1)
promptsubst
似乎存在问题。首次定义RPROMPT="${vcs_info_msg_0_}"
时,vcs_info_msg_0_
将替换RPROMPT
的值。这就是为什么它在您在存储库中打开shell时工作的原因,而在您更改为存储库时则不然。
单引号变体会阻止此初始替换,setopt promptsubst
应在每次使用提示时执行替换。但在你的情况下,它显然没有。可能在zsh配置中的某个位置setopt nopromptsubst
会在prompt_bart_setup
之后调用。
请参阅setopt | grep promptsubst
是否确实已设置。