Guest User

Bash git prompt

a guest
Oct 20th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.73 KB | None | 0 0
  1. # Show uncommitted files
  2. function parse_git_dirty {
  3.     [[ $(/usr/bin/git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
  4. }
  5.  
  6. # Returns "|s:N" where N is the number of stashed states (if any).
  7. function parse_git_stash {
  8.     local stash=`expr $(/usr/bin/git stash list 2>/dev/null| wc -l)`
  9.     if [ "$stash" != "0" ]
  10.     then
  11.         echo "|s:$stash"
  12.     fi
  13. }
  14.  
  15. # Get the current git branch name (if available)
  16. git_prompt() {
  17.     local ref=$(/usr/bin/git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3)
  18.     if [ "$ref" != "" ]
  19.     then
  20.         echo "($ref$(parse_git_dirty)$(parse_git_stash)) "
  21.     fi
  22. }
  23.  
  24. # Show host, cwd and git status
  25. PS1="$PS1PREFIX\h:\w\$(git_prompt)$ "
Advertisement
Add Comment
Please, Sign In to add comment