Skip to content

Instantly share code, notes, and snippets.

@rgthree
Created November 4, 2013 23:02
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 rgthree/7310781 to your computer and use it in GitHub Desktop.
Save rgthree/7310781 to your computer and use it in GitHub Desktop.
.bash_prompt
export TERM=gnome-256color
tput sgr0
RED=$(tput setaf 1)
ORANGE=$(tput setaf 172)
BLUE=$(tput setaf 4)
WHITE=$(tput setaf 7)
GRAY=$(tput setaf 0)
BOLD=$(tput bold)
RESET=$(tput sgr0)
function parse_git_branch() {
# Check that we are in a repo
inrepo="$(git rev-parse --is-inside-work-tree 2>/dev/null)" || return
test "$inrepo" = true || return
# GET BRANCH
branch="$(git symbolic-ref HEAD 2>/dev/null)"
test -z "$branch" && branch='<detached-HEAD>'
state=""
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && state="${state}*"
[[ $(git status | grep Untracked) != "" ]] && state="${state}+"
toReturn=""
color="$BLUE"
if [ "$state" == "*" ]; then
color="$ORANGE"
elif [ "$state" == "*+" ]; then
color="$RED"
fi
echo " ${color}(${branch#refs/heads/}${state})"
}
export PS1="\[$BOLD\]\[$WHITE\]\w\[$ORANGE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]"
export PS2="\[$ORANGE\]→ \[$RESET\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment