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

来源:互联网 发布:如何找淘宝客 编辑:程序博客网 时间:2024/06/08 01:23

修改家目录下面的 .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

原创粉丝点击