2016-03-09 123 views
0

這應該很簡單。 最近我注意到,當我輸入「慶典」到Mac上的終端就說明這一點:bash:parse_git_branch:找不到命令

Jays-MacBook-Pro: ~ $ bash 
bash: parse_git_branch: command not found 

當它沒有之前。有人可以解釋爲什麼以及如何解決。

回答

1

很可能您將BASH配置爲運行parse_git_branch並將結果作爲PS1(或類似部分)的一部分進行打印。您可以通過以下方式檢查:「echo $ PS1」和「echo $ PROMPT_COMMAND」。

但是,parse_git_branch不是bash的內置函數。以下是我如何配置我的PS1。你可能想複製我的git_branch_4_ps1作爲你的parse_git_branch

PS1='\n'       # begin with a newline 
    PS1=$PS1'\[\e[38;5;101m\]\! \t ' # time and command history number 
    PS1=$PS1'\[\e[38;5;106m\]\[email protected]\h ' # [email protected] 
    PS1=$PS1'\[\e[7;35m\]${MY_WARN}\[\e[0m\] ' # warning message if there is any 
    PS1=$PS1'\[\e[38;5;10m\]${MY_EXTRA} '  # extra info if there is any 
    PS1=$PS1'\[\e[0;36m\]$(git_branch_4_ps1) ' # git_branch_4_ps1 defined below 
    PS1=$PS1'\[\e[38;5;33m\]\w'  # working directory 
    PS1=$PS1'\n\[\e[32m\]\$ '   # "$"/"#" sign on a new line 
    PS1=$PS1'\[\e[0m\]'    # restore to default color 

    function git_branch_4_ps1 {  # get git branch of pwd 
     local branch="$(git branch 2>/dev/null | grep "\*" | colrm 1 2)" 
     if [ -n "$branch" ]; then 
      echo "(git: $branch)" 
     fi 
    }