为什么不起作用?提示区域是空的,我没有错误。
setopt prompt_subst
git_prompt() {
temp=`git symbolic-ref HEAD 2>/dev/null | cut -d / -f 3`
if [ "$temp" != "" ]; then
RPROMPT='%{$fg_no_bold[green]%}git:($temp%)%{$reset_color%} %{$fg_no_bold[yellow]%}[%1~]%{$reset_color%}'
else
RPROMPT='%{$fg_no_bold[yellow]%}[%~]%{$reset_color%}'
fi
}
RPROMPT='$(git_prompt)'
RPROMPT 的值拼写正确并且不包含错误。
最佳答案
函数git_prompt
不会产生任何输出,而是直接设置RPROMPT
。然而,您随后将 RPROMPT
设置为 git_prompt
的输出,从而有效地将其设置为空字符串。
要么返回字符串,而不是在 git_prompt
中设置 RPROMPT
。
setopt prompt_subst git_prompt() { temp=`git symbolic-ref HEAD 2>/dev/null | cut -d / -f 3` if [ "$temp" != "" ]; then return '%{$fg_no_bold[green]%}git:($temp%)%{$reset_color%} %{$fg_no_bold[yellow]%}[%1~]%{$reset_color%}' else return '%{$fg_no_bold[yellow]%}[%~]%{$reset_color%}' fi } RPROMPT='$(git_prompt)'
或者只是将 git_prompt
设置为在打印提示之前自动运行:
git_prompt() { temp=`git symbolic-ref HEAD 2>/dev/null | cut -d / -f 3` if [ "$temp" != "" ]; then RPROMPT='%{$fg_no_bold[green]%}git:($temp%)%{$reset_color%} %{$fg_no_bold[yellow]%}[%1~]%{$reset_color%}' else RPROMPT='%{$fg_no_bold[yellow]%}[%~]%{$reset_color%}' fi } autoload -Uz add-zsh-hook add-zsh-hook precmd git_prompt<小时/>
您可能还想查看the vcs_info
function ,它允许您生成带有版本控制信息的提示,而无需自己进行数据检索。
关于linux - zsh提示功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28179617/