Skip to content

Instantly share code, notes, and snippets.

@j4rs
Created Sep 21, 2019
Embed
What would you like to do?
export PS1="\[\033[36m\]\u:\[\033[32m\]\w\[\033[33m\]\$(markup_git_branch \$(parse_git_branch))\[\033[00m\]$ "
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (*\([^)]*\))*/\1/'
}
markup_git_branch() {
if [[ -n $@ ]]; then
if [[ -z $(git status --porcelain 2> /dev/null) ]]; then
echo -e ":\001\033[32m\002($@)\001\033[0m\002"
else
local git_status="$(git status 2> /dev/null)"
local git_status_porcelain="$(git status --porcelain)"
changes=""
if [[ $git_status =~ "modified:" ]]; then
changes+="*"
fi
if [[ $git_status_porcelain =~ "??" ]]; then
changes+="+"
fi
if [[ $git_status =~ "deleted:" ]]; then
changes+="-"
fi
echo -e ":\001\033[31m\002($@$changes)\001\033[0m\002"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment