我试图修改巴特主题,以便它包含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中创建了一个新的终端会话,但是当我更改目录时,它不会更新。
我已经看到了使用单引号的建议,但当我将其更改为:
prompt_bart_ps1 () {
# ...
setopt promptsubst
RPROMPT='${vcs_info_msg_0_}'
# ...
}提示显示字面上的${vcs_info_msg_0_}。有什么想法吗?
发布于 2014-03-10 14:46:06
promptsubst似乎有一个问题。RPROMPT="${vcs_info_msg_0_}"将在首次定义vcs_info_msg_0_时替换RPROMPT的值。这就是为什么当您在存储库中打开一个shell时,而不是当您更改为一个shell时,它才能工作的原因。
单引号变量会阻止这个初始的替换,然后每次使用提示符时,setopt promptsubst都应该进行替换。但在你的情况下显然不是。可能,在zsh配置中的某个位置有一个setopt nopromptsubst,它在prompt_bart_setup中的一个后面调用。
使用setopt | grep promptsubst查看是否真的设置了它。
https://stackoverflow.com/questions/22114884
复制相似问题