【发布时间】:2016-05-14 21:21:17
【问题描述】:
我的终端现在在同一行上写了两次。在开始重复该行之前它也不会走到尽头。这是在我的 .bash_profile 中
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 类型命令设置颜色。
我想做的是让它告诉我什么时候我的 git 脏了。现在它写在我开始的终端的同一行上。即使尝试 [ ] 也会这样做。有人可以告诉我如何解决这个问题以及 PROMPT_COMMAND 行如何工作。
【问题讨论】:
-
这是一个常见的常见问题解答,并不是真正的编程问题。参见例如unix.stackexchange.com/questions/31642/…
标签: git macos terminal osx-elcapitan .bash-profile