[转载] 如何在Bash中显示当前git分支
平时对于oh-my-zsh的依赖并不是很多,因而对于远端CodeServer没必要每次升级后再重装oh-my-zsh,本文转载了一个在bash中显示当前git分支的办法
原作者链接:原文地址
编辑 ~/.bashrc
nano ~/.bashrc
在其中添加:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
保存后,重新开启新的terminal或者 source ~/.bashrc, 即可生效。