-
-
Save Seanstoppable/5545007 to your computer and use it in GitHub Desktop.
This file contains 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
# * 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in function parse_git_dirty(), you need "-z" instead of "-n", I think. As is, the logic seems to be reversed.