Guest User

Untitled

a guest
May 20th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Displays the current git branch name and the dirty state in your Bash shell
  4. # prompt. Add a line like this to your ~/.bashrc file:
  5. #
  6. # . ~/path/to/gist/bash-git-prompt
  7. #
  8. # To use this, you must enable "enable programmable completion features".
  9. # Look at your ~/.bashrc for something like:
  10. #
  11. # if [ -f /etc/bash_completion ]; then
  12. # . /etc/bash_completion
  13. # fi
  14. #
  15. # Since Bash 3.1, Debian has moved the file bash_completion to the bash-completion
  16. # package, so: apt-get install bash-completion
  17. #
  18. # Otherwise, you will get an error for __git_ps1 not being found.
  19.  
  20. if [ -r /etc/bash_completion.d/git ] ; then
  21.  
  22. function __repo_branch ()
  23. {
  24. __git_ps1
  25. }
  26. function __git_prompt_enabled ()
  27. {
  28. # Search for .git-prompt-disable file in parent directories
  29. dir=`pwd`
  30. while [ `dirname "$dir"` != "$dir" ] ; do
  31. if [ -f "$dir/.git-prompt-enable" ] ; then return 0 ; fi
  32. if [ -f "$dir/.git-prompt-disable" ] ; then return 1 ; fi
  33. dir=`dirname "$dir"`
  34. done
  35. }
  36. function __repo_dirty ()
  37. {
  38. __git_prompt_enabled || ( perl -e 'print "? "' ; exit 1 ) || return
  39. status=`git status 2>&1`
  40. if [[ "$status" =~ "Not a git repository" ]] ; then return ; fi
  41. if [[ "$status" =~ "Changed but not updated" ]] ; then perl -e 'print "C "' ; return ; fi
  42. if [[ "$status" =~ "Untracked files" ]] ; then perl -e 'print "u "' ; return ; fi
  43. if [[ "$status" =~ "Changes to be committed" ]] ; then perl -e 'print "i "' ; return ; fi
  44. if [[ "$status" =~ "Your branch is ahead" ]] ; then perl -e 'print "a "' ; return ; fi
  45. }
  46. PS1='${debian_chroot:+($debian_chroot)}\[\033[00;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;33m\]$(__repo_branch)\[\033[01;31m\]$(__repo_dirty)\[\033[00m\]\$ '
  47.  
  48. fi
Add Comment
Please, Sign In to add comment