Guest User

Untitled

a guest
Jul 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. # Show current git branch or SVN subfolder in prompt.
  2. GREEN="\[\033[0;32m\]"
  3. LIGHT_GREEN="\[\033[1;32m\]"
  4. GRAY="\[\033[1;30m\]"
  5. LIGHT_BLUE="\[\033[1;34m\]"
  6. LIGHT_GRAY="\[\033[0;37m\]"
  7. COLOR_OFF="\[\e[0m\]"
  8. function prompt_func() {
  9. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  10.  
  11. branch_pattern="\* ([^$IFS]*)"
  12. if [[ -d "./.git" && "$(git branch --no-color 2> /dev/null)" =~ $branch_pattern ]]; then
  13. branch="${BASH_REMATCH[1]}"
  14. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
  15. PS1+=":$GRAY$branch$LIGHT_GRAY@$revision$COLOR_OFF\$ "
  16.  
  17. elif [[ -d "./.svn" ]]; then
  18. PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
  19. path_pattern="URL: ([^$IFS]*).*Repository Root: ([^$IFS]*).*Revision: ([0-9]*)"
  20. if [[ "$(svn info 2> /dev/null)" =~ ${path_pattern} ]]; then
  21. branch=`/usr/bin/ruby -e 'print ARGV[0][ARGV[1].size + 1..-1] || "/"' ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}`
  22. revision="${BASH_REMATCH[3]}"
  23. PS1+=":$GRAY$branch$LIGHT_GRAY@$revision$COLOR_OFF\$ "
  24. fi
  25. fi
  26. }
  27. PROMPT_COMMAND=prompt_func
Add Comment
Please, Sign In to add comment