我的終端現在正在同一行寫兩次。在它開始重複這條線之前,它也沒有走到盡頭。這是在我的.bash_profile與bash配置文件相同的終端寫入升級。
c_reset="$(tput setaf 2)"
c_path="$(tput setaf 1)"
c_git_dirty="$(tput setaf 1)"
c_git_clean="$(tput setaf 2)"
c_white="$(tput setaf 7)"
PROMPT_COMMAND=$PROMPT_COMMAND' PS1="${c_path}\W${c_reset}$(git_prompt) :> "'
export PS1='\n\[\033[0;31m\]\W\[\033[0m\]$(git_prompt)\[\033[0m\]:> '
git_prompt()
{
# Is this a git directory?
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
# Grab working branch name
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
# Clean or dirty branch
if git diff --quiet 2>/dev/null >&2; then
git_color="${c_git_clean}"
else
git_color=${c_git_dirty}
fi
echo "${c_white}[$git_color$git_branch${c_white}]"
}
我得到了什麼代碼劑量。但我的問題是它仍然寫在同一行。我已經嘗試了其他的做法。使用\ 003 [0; 31m type命令設置顏色。
我想要做的是讓它告訴我什麼時候我的git很髒。現在它在我開始的終端上寫同一行。它甚至在嘗試[]時也會這樣做。有人可以告訴我如何解決這個問題,以及PROMPT_COMMAND如何工作。
這是一種常見的常見問題,並沒有真正一個編程問題。見例如http://unix.stackexchange.com/questions/31642/bash-prompt-command-messing-up-scroll-history-display – tripleee