xywuyiba8 发表于 2018-1-14 12:27:45

centos ssh终端下高亮显示git分支名

#set git branch  
green=$'\e[1;32m'
  
magenta=$'\e[1;35m'
  
normal_colours=$'\e[m'
  

  
function find_git_branch {
  
local dir=. head
  
until [ "$dir" -ef / ]; do
  
if [ -f "$dir/.git/HEAD" ]; then
  
head=$(< "$dir/.git/HEAD")
  
if [[ $head == ref:\ refs/heads/* ]]; then
  
git_branch=" ${head#*/*/}"
  
elif [[ $head != '' ]]; then
  
git_branch=' (detached)'
  
else
  
git_branch=' (unknown)'
  
fi
  
return
  
fi
  
dir="../$dir"
  
done
  
git_branch=''
  
}
  

  
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
  
PS1="\[$green\]\u@\h:\w\[$magenta\]\$git_branch\[$green\]\\[$normal_colours\] "
  
页: [1]
查看完整版本: centos ssh终端下高亮显示git分支名