-
-
Save dpkirchner/6495319 to your computer and use it in GitHub Desktop.
Got tired of leaving stashes lying around.
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
# http://henrik.nyh.se/2008/12/git-dirty-prompt | |
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ | |
# username@Machine ~/dev/dir[master]$ # clean working directory | |
# username@Machine ~/dev/dir[master*]$ # dirty working directory | |
# username@Machine ~/dev/dir[master*] (stashes 2)$ # dirty working dir plus there are some stashes | |
function parse_git_dirty { | |
[ ! -z "$(git status --porcelain 2> /dev/null)" ] && echo "*" | |
} | |
# http://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch | |
function parse_git_branch { | |
x=$(git rev-parse >/dev/null 2>&1) | |
[ $? != 0 ] && return # Not in a repo | |
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || | |
branch_name="(unnamed branch)" # detached HEAD | |
branch_name=${branch_name##refs/heads/} | |
echo $branch_name | sed -e "s/^\(.*\)$/[\1$(parse_git_dirty)]/" | |
} | |
function parse_git_stash { | |
n=$(git stash list 2> /dev/null | wc -l | sed 's/ //g') | |
[ ! -z "$n" -a "$n" != "0" ] && echo " (stashes: $n)" | |
} | |
function parse_git_status { | |
x=$(git rev-parse >/dev/null 2>&1) | |
[ $? != 0 ] && return # Not in a repo | |
[ -e $(git rev-parse --git-dir)/rebase-merge ] && echo " (rebasing)" | |
} | |
export PS1='\u@\h:\w \[\033[1;33m\]`parse_git_branch``parse_git_stash``parse_git_status`\[\033[0m\]\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment