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

ssh终端显示git分支名:

 1 #set git branch
 2 green=$'\e[0;32m'
 3 magenta=$'\e[0;36m'
 4 normal_colours=$'\e[m'
 5 
 6 function find_git_branch {
 7     local dir=. head
 8     until [ "$dir" -ef / ]; do
 9         if [ -f "$dir/.git/HEAD" ]; then
10             head=$(< "$dir/.git/HEAD")
11             if [[ $head == ref:\ refs/heads/* ]]; then
12                 git_branch="(${head#*/*/})#"
13             elif [[ $head != '' ]]; then
14                 git_branch='(detached)'
15             else
16                 git_branch='(unknown)'
17             fi
18             return
19         fi
20         dir="../$dir"
21     done
22     git_branch='#'
23 }
24 
25 PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
26 PS1="\[$green\][\u@\h \W]\[$magenta\]\$git_branch\[$green\]\\[$normal_colours\] "

将上面这段,追加 /etc/profile 或 ~/.bash_profie 或 ~/.bashrc 任何一个的最后,然后source /etc/profile (或source ~/.bash_profile 或 source ~/.bashrc),让其生效即可。

最终效果:

 

git color的配置

Git多颜色输出

Git默认的输出是单一颜色的,不仅不够美观,也不容易阅读。实际上,Git本身就支持用多种颜色来显示其输出的信息,只需在命令行中运行以下命令来修改git的设置,即可开启多颜色输出:

git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto

  

执行以上命令后,git的status, diff和branch等诸命令的输出就都是带有颜色的了。

-------------------------------------------

需要在命令行窗口中运行命令,用来保存账密:

git config --global credential.helper store

 
posted @ 2020-12-03 14:42  祁连雪狼之家  阅读(325)  评论(0编辑  收藏  举报