Last active
April 26, 2018 03:34
-
-
Save petehalverson/3fbd4dcd5e8bb9c110434d7491c8040f to your computer and use it in GitHub Desktop.
git_branch profile script
This file contains hidden or 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
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) $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed line wrap. Ref: http://mywiki.wooledge.org/BashFAQ/053