在 Shell 提示符中显示 Git 分支名称的方法
来源:互联网 发布:linux 修改时间 编辑:程序博客网 时间:2024/06/05 08:10
PS1介绍
PS1介绍
配置
获取branch名称
通过git branch获取(不推荐)
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
通过.git/HEAD 获取(推荐)
vi .git/HEAD############ef: refs/heads/dev############
配置.bashrc
vim ~/.bashrc#######################获取branch名称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="unknow" fi git_name_left="git:(" git_name_right=")" return fi dir="../$dir" done git_branch='' git_name_left="" git_name_right=""}#将这个函数加入到 PROMPT_COMMAND 中,保证 Bash 在创建 prompt 之前调用这个函数取得分支名称:PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"#颜色配置black=$'\[\e[1;30m\]'red=$'\[\e[1;31m\]'green=$'\[\e[1;32m\]'yellow=$'\[\e[1;33m\]'blue=$'\[\e[1;34m\]'magenta=$'\[\e[1;35m\]'cyan=$'\[\e[1;36m\]'white=$'\[\e[1;37m\]'normal=$'\[\e[m\]'#配置PS1PS1="$green➜ $cyan\W$blue \$git_name_left$red\$git_branch$blue\$git_name_right\$ $normal"####################source ~/.bashrc
Git仓库效果:
非Git仓库效果
阅读全文
0 0
- 在 Shell 提示符中显示 Git 分支名称的方法
- shell脚本----在 Shell 提示符中显示 Git 分支名称
- 让 shell 显示当前 git 的分支名称
- 在SHELL的提示符上显示完整路径
- 在LINUX的命令提示符及CMD命令提示符中显示时间
- Git修改分支名称
- 修改adb shell在pc端显示的名称
- 在mac终端显示git分支
- 根文件系统中命令行提示符的显示
- source tree中 git 不显示分支
- shell提示符显示本机ip地址的问题
- Shell 显示所在项目当前git分支及状态
- windows如何在cmd命令行提示符中显示当前的时间
- windows如何在cmd命令行提示符中显示当前的时间
- Solaris 在当前用户提示符中显示当前目录
- 在VC中不显示命令提示符窗口
- Ubuntu下显示git分支的状态
- 如何在数据窗口中显示编码的名称
- leetcode -- 628. Maximum Product of Three Numbers
- Scala——闭包
- VMware虚拟机中设置端口映射----本人备注!!!
- java&javac&jar命令总结
- HNUST 手势密码
- 在 Shell 提示符中显示 Git 分支名称的方法
- OC语言学习08-属性约束
- ARM处理器工作模式
- JavaScript函数的副作用分析
- javaScript简介(第一章)
- CentOS6下安装ffmpeg
- EhCache初体验
- Scala——集合
- The requested URL /**** was not found on this server