oh-my-zsh顯示github分支時,若是當前文件夾不是git倉庫,它就會顯示亂碼。倒騰了好幾個小時終於弄清楚是oh-my-zsh中函數」git_prompt_info「的鍋,而後又花了半個多小時調代碼,如今總算像我的了!!git
function git_prompt_info() { local ref if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ if [[ -n $ref ]]; then ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0 fi if [[ -n ${ref#refs/heads/} ]]; then echo " ${ref#refs/heads/}" fi fi }
這裏修改顯示邏輯,若是當前文件夾屬於git倉庫,就顯示分支,不然什麼也不顯示。github
local ret_status="%(?:%{$fg_bold[green]%}➜:%{$fg_bold[red]%}➜)" PROMPT='${ret_status} %{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info) %{$reset_color%}$ ' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
這裏是修改prompt格式,直接拷貝進去就好,不要漏空格,不然會很醜。bash