2013-11-25 50 views
1

我在週末升級到了10.9,並且我的bash提示顯示有點時髦。我現在有這在我的.bash_profileOS X Mavericks:如果未提交更改,Git bash提示已停止跟蹤

function parse_git_dirty { 
    [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*" 
} 
function parse_git_branch { 
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/" 
} 

PS1="\n\[\e[1;34m\]\$(date +%H:%M) \[\e[1;36m\]\w\[\e[1;33m\] \$(parse_git_branch) \[\e[1;31m\]\$(rvm_version)\n\[\e[0;32m\]> \[\e[0m\]" 
unset color_prompt force_color_prompt 

這曾經(10.8)產生看起來是這樣的一個提示:

07:45 ~/code/project_dir [git-branch] [email protected] 

如果存在需要被提交到我的git變化分支,它會附加星號([git-branch*])。

因爲升級,但是,它總是已在*分支後列出。其他一切似乎都像正常一樣運作。我怎樣才能讓它像以前一樣行事?

我已經更新到最新版本的git。

+0

同樣的問題在http://apple.stackexchange.com/q/111762/7057 –

+0

使用你的代碼在10.8.5下,我也一直得到'*',所以這不是小牛的問題。 – trojanfoe

回答

0

每@chepner,我切換到經由自制的bash中完成封裝使用git-prompt.sh

1

這看起來像git版本的變化。當我在OS X 10.9(GIT 1.8.3.4)運行git status,從一個乾淨的存儲庫中的消息是

nothing to commit, working directory clean 
+0

必須有一個更好的方法來做到這一點,它不依賴於字符串比較... – trojanfoe

+0

可能,但即使是'git'附帶的'git-prompt.sh'腳本也會解析'git status用於確定哪些(如果有的話)文件處於未分配狀態和未提交狀態(至少在最後一次檢查時)。 – chepner

+0

第二次看,似乎'git-prompt.sh'已經清理了它的行爲,或者我正在看另一個腳本。在任何情況下,OP都應考慮在Git分發中使用(或至少學習)'contrib/completion/git-prompt.sh'來找到構建其提示的更健壯的方法。 – chepner