zshrc - 尾随字符和缺失:endfunction

问题描述 投票:0回答:1
function Show_current_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/(\1)/p'
}

setopt PROMPT_SUBST
PROMPT='%f%B%3~%b%f %F{#76946A}$(Show_current_branch) %f%F{#76946A}> '

当我重新加载 zshrc 时,出现以下错误消息: source ~/.zshrc

  1. 处理 /Users/user/.zshrc 时检测到错误
  2. 尾随字符:{ E126:缺少:endfunction }

我已经尝试过:

function Show_current_branch()
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/(\1)/p'
endfunction
zsh zshrc
1个回答
0
投票

正如我所言,您可以在函数定义末尾添加

:endfunction
标签

function Show_current_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/(\1)/p'
}
endfunction

setopt PROMPT_SUBST
PROMPT='%f%B%3~%b%f %F{#76946A}$(Show_current_branch) %f%F{#76946A}> '

现在保存并退出,然后输入此命令重新加载

zshrc

source ~/.zshrc
© www.soinside.com 2019 - 2024. All rights reserved.