Skip to content

Instantly share code, notes, and snippets.

@jsvisa
Last active November 9, 2018 06:26
Show Gist options
  • Save jsvisa/4bfb3717675b719a07d0cad631d85bfd to your computer and use it in GitHub Desktop.
Save jsvisa/4bfb3717675b719a07d0cad631d85bfd to your computer and use it in GitHub Desktop.
parse git branch in bash PS1
# ~/.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
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