/.bash_prompt

https://github.com/Ephemera/dotfiles · #! · 71 lines · 65 code · 6 blank · 0 comment · 0 complexity · 97222c587b2b1b7892c6ba4b0d574bc9 MD5 · raw file

  1. # Fork from https://github.com/gf3/dotfiles/blob/master/.bash_prompt
  2. # Sexy Bash Prompt, inspired by "Extravagant Zsh Prompt"
  3. # Screenshot: http://img.gf3.ca/d54942f474256ec26a49893681c49b5a.png
  4. # A big thanks to \amethyst on Freenode
  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. if tput setaf 1 &> /dev/null; then
  9. tput sgr0
  10. if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
  11. MAGENTA=$(tput setaf 9)
  12. ORANGE=$(tput setaf 172)
  13. GREEN=$(tput setaf 190)
  14. PURPLE=$(tput setaf 141)
  15. WHITE=$(tput setaf 256)
  16. #WHITE=$(tput setaf 0)
  17. CYAN=$(tput setaf 6)
  18. else
  19. MAGENTA=$(tput setaf 5)
  20. ORANGE=$(tput setaf 4)
  21. GREEN=$(tput setaf 2)
  22. PURPLE=$(tput setaf 1)
  23. WHITE=$(tput setaf 7)
  24. CYAN=$(tput setaf 6)
  25. fi
  26. BOLD=$(tput bold)
  27. RESET=$(tput sgr0)
  28. else
  29. MAGENTA="\033[1;31m"
  30. ORANGE="\033[1;33m"
  31. GREEN="\033[1;32m"
  32. PURPLE="\033[1;35m"
  33. WHITE="\033[1;37m"
  34. CYAN="\033[1;36m"
  35. BOLD=""
  36. RESET="\033[m"
  37. fi
  38. parse_git_dirty () {
  39. [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
  40. }
  41. parse_git_branch () {
  42. git branch -v --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \([^ ]*\)\ *\([^ ]*\) \(.*\)/\1:\2$(parse_git_dirty)/"
  43. }
  44. parse_git_just_branch () {
  45. git branch --contains 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1:$(parse_git_hash)$(parse_git_dirty)/"
  46. }
  47. parse_git_hash() {
  48. git rev-parse --short HEAD 2> /dev/null
  49. }
  50. parse_git_hash1 () {
  51. ((git log --pretty=format:'%h' -n 1)) && git log --pretty=format:'%h' -n 1
  52. }
  53. parse_hg_dirty () {
  54. [[ $(hg status 2> /dev/null | head -n1 | cut -c 1) == "M" ]] && echo "*"
  55. }
  56. parse_hg_branch () {
  57. hg branch 2> /dev/null | sed -e "s/\(.*\)/\1$(parse_hg_dirty)/"
  58. }
  59. jobscount() {
  60. local stopped=$(jobs -sp | wc -l)
  61. local running=$(jobs -rp | wc -l)
  62. ((running+stopped)) && echo "${running}r/${stopped}s"
  63. }
  64. #PS1="\[${PURPLE}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\$([[ -n \$(hg branch 2> /dev/null) ]] && echo \" on \")\[$CYAN\]\$(parse_hg_branch)\[$WHITE\]\n\#> \[$RESET\]"
  65. PS1="\n\$([ \j -gt 0 ] && echo [\j]\ )\u@\h:\w\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" - \")\$(parse_git_just_branch)\n\#> "