Henrik has a great article explaining why and how to display Git’s dirty state status (along with the branch, of course) in your bash prompt.
Here’s his Gist:
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":http://github.com/Machine ~/dev/dir[master]$ # clean working directory
username"Machine":http://github.com/Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != “nothing to commit (working directory clean)” ]] && echo “*”
}
function parse_git_branch {
git branch —no-color 2> /dev/null | sed -e ‘/^[^*]/d’ -e “s/* \(.*\)/[\1$(parse_git_dirty)]/”
}
export PS1=’\u@\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ ’
topfunky prefers a skull and bones for his dirty state indicator. zsh code here
Thanks guys!
I feel sorry for all y’all non-Emacs users …
There’s also __git_ps1 for the branch name — little easier. Found it here: http://blog.ericgoodwin.com/2008/4/10/auto-completion-with-git
Not only would I recommend using __git_ps1 from the official git.git but to get the “dirty” indicator in there! ;-)
The dirty marker makes me happy.
Nice. I have mine setup to color the branch name. Red means I have local changes; green means no local changes. Screenshot: http://bit.ly/3h9a
Getting into the spirit, http://gist.github.com/48207 will give you +-* characters if you have added, removed or modified files that aren’t yet added to the next commit:
I’m not sure how to colour code the + green, – red and * yellow. Anyone know how?
Is this what you are looking for?
#!/usr/bin/ruby
printf “\033[0m0 All attributes off\033[0m\n” printf “\033[1m1 Bold\033[0m\n” printf “\033[4m4 Underline\033[0m\n” printf “\033[5m5 Blink\033[0m\n” printf “\033[7m7 Invert\033[0m\n” printf “\033[8m8 Hide\033[0m8 = Hide\n” printf “\033[30m30 Black\033[0m30 = Black\n” printf “\033[31m31 Red\033[0m\n” printf “\033[32m32 Green\033[0m\n” printf “\033[33m33 Yellow\033[0m\n” printf “\033[34m34 Blue\033[0m\n” printf “\033[35m35 Magenta\033[0m\n” printf “\033[36m36 Cyan\033[0m\n” printf “\033[37m37 White\033[0m\n” printf “\033[40m\033[37m40 Black Background\033[0m\n” printf “\033[41m41 Read Background\033[0m\n” printf “\033[42m42 Green Background\033[0m\n” printf “\033[43m43 Yellow Background\033[0m\n” printf “\033[44m44 Blue Background\033[0m\n” printf “\033[45m45 Magenta Background\033[0m\n” printf “\033[46m46 Cyan Background\033[0m\n” printf “\033[47m47 White Background\033[0m\n”
Sorry, let me try again
@drnic Here’s the snippet of bash I’m using to color my branch name: http://gist.github.com/48999