Skip to content

Instantly share code, notes, and snippets.

@Val-istar-Guo
Last active March 1, 2017 05:18
Show Gist options
  • Save Val-istar-Guo/fe35b4b712f82b7e17afdf50b9ad7caa to your computer and use it in GitHub Desktop.
Save Val-istar-Guo/fe35b4b712f82b7e17afdf50b9ad7caa to your computer and use it in GitHub Desktop.
Show Git Branch on Terminal
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/:\1/' -e 's/((/(/' -e 's/))/)/'
}
function proml {
local LIGHT_RED="\[\e[1;37m\]"
local RED="\[\033[1;32m\]"
local COLOR_END="\[\e[0m\]"
PS1="[\u@$LIGHT_RED\W$COLOR_END$RED\$(parse_git_branch)$COLOR_END]\$ "
}
proml

Show Git Branch on Terminal

Use

将.bash_profile文件中的内容复制到本地 ~/.bash_profile中即可。

Personalization

如果你不想使用xxxxxxx:BranchName 的形式,你可以修改 parse_git_branch函数中的sed命令。 对sed命令第二个-e后面的字符串中的/:\1/部分进行修改。两侧的反斜杠是一个界限,不要修改,也不要在此之外做修改。\1代表着BranchName前后添加你希望添加的字符就可以(使用转义字符请自行参考sed命令)。这些字符在非git项目的目录是不会显示的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment