• Dirty Git State in Your Prompt

    defunkt 14 Jan 2009

    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:

    topfunky prefers a skull and bones for his dirty state indicator. zsh code here

    Thanks guys!

  • Comments

    offby1 Wed Jan 14 17:21:57 -0800 2009

    I feel sorry for all y’all non-Emacs users …

    richpoirier Wed Jan 14 23:06:49 -0800 2009

    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

    awendt Thu Jan 15 02:31:39 -0800 2009

    Not only would I recommend using __git_ps1 from the official git.git but to get the “dirty” indicator in there! ;-)

    drnic Thu Jan 15 04:40:51 -0800 2009

    The dirty marker makes me happy.

    codebrulee Thu Jan 15 08:00:55 -0800 2009

    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

    drnic Fri Jan 16 15:25:47 -0800 2009

    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:

    ~/macruby_apps/CommitChat[master*]$ touch foo
    ~/macruby_apps/CommitChat[master+*]$ rm progress.gif 
    ~/macruby_apps/CommitChat[master+*-]$ 
    drnic Fri Jan 16 15:26:12 -0800 2009

    I’m not sure how to colour code the + green, – red and * yellow. Anyone know how?

    gcao Sat Jan 17 06:49:21 -0800 2009

    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”

    gcao Sat Jan 17 06:50:54 -0800 2009

    Sorry, let me try again

    #!/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"
    
    codebrulee Mon Jan 19 05:55:10 -0800 2009

    @drnic Here’s the snippet of bash I’m using to color my branch name: http://gist.github.com/48999

    Marie-Curie Sun Oct 25 09:44:59 -0700 2009

    Marie Curie say: Thank a lot, it is so usefull for me, keep it going on, I love you,

    Please log in to comment.