Created
October 18, 2010 02:49
-
-
Save indirect/631628 to your computer and use it in GitHub Desktop.
improved git prompt yay
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
# [andre ~/.bash](master)$ # clean working directory | |
# [andre ~/.bash](master⚡)$ # dirty working directory | |
# [andre ~/.bash](master~2)$ # checked out revision not a branch | |
# [andre ~/.bash](branch)$ # checked out branch with same commits as master | |
function parse_git_dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡" | |
} | |
function parse_git_branch { | |
local b="$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/^* //')" | |
if [ -n "$b" ] && [ "$b" = "(no branch)" ]; then | |
local b="$(git name-rev --name-only HEAD 2> /dev/null)" | |
fi | |
if [ -n "$b" ]; then | |
printf "($b$(parse_git_dirty))" | |
fi | |
} | |
export PS1='\[\033k\033\\\]\[\e[0;34m\][\u \w]$(parse_git_branch)\$\[\e[0;39m\] ' |
The main reason I wrote my own is that __git_ps1
doesn't support non-branch locations, like master~2
. If that's changed, I'm a happy man. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may already know about these:
Although the dirty state chars might not be as fancy as yours :p