#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\] "

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

最终效果:

  

最新文章

  1. java的remote shell
  2. Python 去剑式
  3. 判断是否含有中文,包含返回true,不包含返回false
  4. mvc5引用ExtJS6
  5. cocoapods 终极方案
  6. ibatis报错
  7. Top 100 English Verbs
  8. 定制化Azure站点Java运行环境(4)
  9. Java图形化界面设计——布局管理器之null布局(空布局)
  10. untiy 播放视频
  11. iOS8的屏幕旋转的问题
  12. setChecked方法触发onCheckedChanged监听器问题
  13. Java GC算法 垃圾收集器
  14. popupwindow那些坑
  15. vue 内联样式style中的background
  16. java某些基础知识点整理
  17. spark-MLlib之线性回归
  18. linux命令--xargs的使用
  19. EF 传递的主键值的数量必须与实体上定义的主键值的数量匹配 原因
  20. C语言实例:数组与字符串

热门文章

  1. Python 入门基础2 --基本数据类型、运算符
  2. Contrastive Loss (对比损失)
  3. Linux输出重定向&gt;和&gt;&gt;的区别是什么
  4. SQLServer xp_instance_regread returned error 5,Access is denied(配置最小权限)
  5. hdu 4348 To the moon (主席树)
  6. (windows下)安装mysql
  7. ajax调用WebService 不能跨域
  8. win10编译caffe跑faster-rcnn(cuda7.5)
  9. Atom组件
  10. Linux下jdk、Tomcat、MySQL的安装