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

修改家目录下面的 .bash_profile添加下方代码


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="[\[$white\]\u@\h:\w\[$magenta\]\$git_branch\[$green\]\\[$normal_colours\] ]$ "
添加完成后 运行source .bash_profile

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页