Skip to content

Instantly share code, notes, and snippets.

@petehalverson
Last active April 26, 2018 03:34
Show Gist options
  • Save petehalverson/3fbd4dcd5e8bb9c110434d7491c8040f to your computer and use it in GitHub Desktop.
Save petehalverson/3fbd4dcd5e8bb9c110434d7491c8040f to your computer and use it in GitHub Desktop.
git_branch profile script
git_branch() {
local green=$(tput setaf 10)
local yellow=$(tput setaf 11)
local reset=$(tput sgr0)
local branch=
local gitlabel="git."
local sep="| "
if [ -d .git ]; then
status=$(git status 2> /dev/null)
branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [[ $( echo $status | grep "branch is ahead") ]]; then
branch="$branch*"
fi
if [[ $( echo $status | grep "working tree clean") ]]; then
branch=$(printf '\001%s\002%s\001%s\002' "$gitlabel" "$green" "$branch" "$reset")
else
branch=$(printf '\001%s\002%s\001%s\002' "$gitlabel" "$yellow" "$branch" "$reset")
fi
fi
if ! [ -z "$branch" ]; then echo -e " $sep$branch"; fi
}
PS1="\h:\W\$(git_branch) $ "
@petehalverson
Copy link
Author

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