Skip to content

Instantly share code, notes, and snippets.

@Seanstoppable
Forked from pbkhrv/gist:5542785
Created May 9, 2013 01:57
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 Seanstoppable/5545007 to your computer and use it in GitHub Desktop.
Save Seanstoppable/5545007 to your computer and use it in GitHub Desktop.
# * uncommitted changes
# ^ stashed changes
# > ahead of origin
# < behind origin
# ↕ diverged from origin
function parse_git_dirty() {
[[ -n $(echo $1 | grep 'nothing to commit (working directory clean)' 2> /dev/null) ]] && echo "*"
}
function parse_git_stash (){
[[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "^"
}
function parse_git_ahead() {
[[ -n $(echo $1 | grep 'Your branch is ahead of' 2> /dev/null) ]] && echo ">"
}
function parse_git_behind() {
[[ -n $(echo $1 | grep 'Your branch is behind' 2> /dev/null) ]] && echo "<"
}
function parse_git_diverge() {
[[ -n $(echo $1 | grep 'have diverged' 2> /dev/null) ]] && echo "↕"
}
function current_git_branch() {
git rev-parse --abbrev-ref HEAD 2> /dev/null
}
function current_git_branch_with_markers {
git_status=`git status 2> /dev/null`
stash=`parse_git_stash`
ahead=`parse_git_ahead "$git_status"`
behind=`parse_git_behind "$git_status"`
diverge=`parse_git_diverge "$git_status"`
dirty=`parse_git_dirty "$git_status"`
echo `current_git_branch` | sed -e "s/\(.*\)/ \[\1$ahead$behind$diverge$dirty$stash\]/"
}
function set_prompt {
local GREEN='\[\e[0;32m\]'
local RED='\[\e[0;31m\]'
local NORMAL='\[\e[0m\]'
PS1="\h:\W \u\[\033[0;32m\]\$(current_git_branch_with_markers) \[\033[0m\]\$ "
}
set_prompt
@pbkhrv
Copy link

pbkhrv commented May 9, 2013

in function parse_git_dirty(), you need "-z" instead of "-n", I think. As is, the logic seems to be reversed.

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