Git and SVN Status in the Bash Prompt


/ Published in: Bash
Save to your folder(s)

Put this into your ~/.bashrc script and you should see the Git/SVN status in your prompt if your working directory is a sandbox.


Copy this code and paste it in your HTML
  1. # Prompt setup, with SCM status
  2. parse_git_branch() {
  3. local DIRTY STATUS
  4. STATUS=$(git status 2>/dev/null)
  5. [ $? -eq 1 ] || return
  6. [[ "$STATUS" == *'working directory clean'* ]] || DIRTY=' *'
  7. echo "($(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* //')$DIRTY)"
  8. }
  9.  
  10. parse_svn_revision() {
  11. local DIRTY REV=$(svn info 2>/dev/null | grep Revision | sed -e 's/Revision: //')
  12. [ "$REV" ] || return
  13. [ "$(svn st)" ] && DIRTY=' *'
  14. echo "(r$REV$DIRTY)"
  15. }
  16.  
  17. PS1='\u@\h:\W$(parse_git_branch)$(parse_svn_revision) \$ '
  18.  
  19. # alternative version of parse_svn_revision()
  20. parse_svn_revision() {
  21. local REV=$(svnversion 2>/dev/null)
  22. [ $? -eq 0 ] || return
  23. [ "$REV" == 'exported' ] && return
  24. echo "($REV)"
  25. }

URL: http://www.entropy.ch/blog/Developer/2009/03/30/Git-and-SVN-Status-in-the-Bash-Prompt.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.