Last active
November 9, 2018 06:26
-
-
Save jsvisa/4bfb3717675b719a07d0cad631d85bfd to your computer and use it in GitHub Desktop.
parse git branch in bash PS1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.gitconfig | |
[alias] | |
sm = smart-merge | |
sp = smart-pull | |
sl = smart-log | |
gs = status | |
co = checkout | |
st = status | |
ci = commit | |
cl = clone | |
cp = cherry-pick | |
br = branch | |
fe = fetch | |
lg = smart-log | |
sh = stash | |
df = diff | |
dt = difftool | |
mt = mergetool | |
pu = push | |
pl = pull | |
sub = submodule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch { | |
local branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/") | |
if [[ $branch ]]; then | |
local tag=$(git describe --tags 2> /dev/null) | |
local status=$(git status --porcelain 2> /dev/null) | |
if [[ "$status" != "" ]]; then | |
echo " <$branch($tag) ✖️ >" | |
else | |
echo " <$branch($tag) ✔️ >" | |
fi | |
fi | |
} | |
BRED='\[\e[1;31m\]' | |
WHITE='\[\e[0;37m\]' | |
export PS1="\u@${BRED}\H${WHITE}:\W\$(parse_git_branch)# " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment