Customized Sexy Bash Prompt - Git branch/Status


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

customized version of Sexy Bash Prompt


Copy this code and paste it in your HTML
  1. # Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
  2. # Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
  3. # A big thanks to \amethyst on Freenode
  4.  
  5. if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
  6. elif infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
  7. fi
  8.  
  9. if tput setaf 1 &> /dev/null; then
  10. tput sgr0
  11. if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
  12. MAGENTA=$(tput setaf 9)
  13. ORANGE=$(tput setaf 172)
  14. GREEN=$(tput setaf 190)
  15. PURPLE=$(tput setaf 141)
  16. WHITE=$(tput setaf 256)
  17. else
  18. MAGENTA=$(tput setaf 5)
  19. ORANGE=$(tput setaf 4)
  20. GREEN=$(tput setaf 2)
  21. PURPLE=$(tput setaf 1)
  22. WHITE=$(tput setaf 7)
  23. fi
  24. BOLD=$(tput bold)
  25. RESET=$(tput sgr0)
  26. else
  27. MAGENTA="\033[1;31m"
  28. ORANGE="\033[1;33m"
  29. GREEN="\033[1;32m"
  30. BLUE="\033[1;34m"
  31. PURPLE="\033[1;35m"
  32. WHITE="\033[1;37m"
  33. BOLD=""
  34. RESET="\033[m"
  35. fi
  36.  
  37. parse_git_dirty () {
  38. [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
  39. }
  40. parse_git_branch () {
  41. git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
  42. }
  43.  
  44. # PS1='${debian_chroot:+($debian_chroot)}\u\[\]@\[$BOLD\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  45.  
  46. PS1="\[$WHITE\]\[$BOLD\]\u\[$RESET\]@\[$WHITE\]\[$BOLD\]\h\[$RESET\]:\[\033[01;34m\]\[$BOLD\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" \[$RESET\]on \")\[$WHITE\]\[$BOLD\]\$(parse_git_branch)\[$RESET\]\n\$ \[$RESET\]"
  47.  
  48. # [End] Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.