Skip to content

Instantly share code, notes, and snippets.

@j4rs
Created September 21, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j4rs/0c276d7b72632f7044a48f4aae774c74 to your computer and use it in GitHub Desktop.
Save j4rs/0c276d7b72632f7044a48f4aae774c74 to your computer and use it in GitHub Desktop.
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