混帳回購協議的髒狀態,如果我用的git回購運行此命令行1.4.3在命令行中,
git status 2> /dev/null | grep -iw 'modified'
輸出我得到
# modified: .rvmrc
,所以我的假設是,如果我插入這在進入if語句我會得到真正的將要執行的代碼
行了,但是當我創建函數作爲.bash_profile中的一部分,這裏是我的代碼有:
## Prompt ##
path="$white\w$reset"
folder_name="$white\W$reset"
git_branch="\$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/$red(\1)$reset/')"
rvm="$green(\$(~/.rvm/bin/rvm-prompt i v p))$reset"
# Checks if working tree is dirty
function _git_st {
if [[ $(git status 2> /dev/null | grep -iw 'modified') ]]; then
echo "[x]"
fi
}
git_st="$yellow`_git_st`$reset"
PS1="$rvm $folder_name $git_branch $git_st \$ "
X沒有迴應....我有點失落,不知道我做錯了什麼。
這是出把我得到:
(ruby-1.9.2-p290) folder-git (master) $ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: .rvmrc
#
no changes added to commit (use "git add" and/or "git commit -a")
(ruby-1.9.2-p290) folder-git (master) $
另外,你的'_git_st'函數比它需要的複雜一點。 '如果git status 2>/dev/null | grep -qiw'修改';那麼'應該工作相同,而不需要捕獲輸出並檢查它是否爲空。 – chepner
謝謝@chepner明天我會試試這個。 – GnrlBzik