A collection of scripts and configurations for Bash (and others)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

95 Zeilen
2.6KB

  1. # define symbols
  2. declare -A symbols=(
  3. [hard_separator]="▶"
  4. [soft_separator]="|"
  5. [git]=""
  6. [lock]=""
  7. [flag]="⚑"
  8. [plus]="✚"
  9. [tick]="✔"
  10. [cross]="✘"
  11. [enter]="⏎"
  12. [python]="λ"
  13. [battery_charging]="⚡"
  14. [battery_discharging]="▮"
  15. [untracked]="U"
  16. [stash]="🐿"
  17. [ahead]="+"
  18. [behind]="-"
  19. [smilie]="☺"
  20. [frownie]="☹"
  21. )
  22. # This function was modified from one found @ https://www.reddit.com/r/linux/comments/2uf5uu/this_is_my_bash_prompt_which_is_your_favorite/?st=jikgswh4&sh=371ba8bf
  23. function _git_status() {
  24. local unknown untracked stash clean ahead behind staged dirty diverged
  25. unknown=$(_CC $BLUE $BG_DGREY)
  26. untracked=$(_CC $GREEN $BG_DGREY)
  27. stash=$(_CC $GREEN $BG_DGREY)
  28. clean=$(_CC $GREEN $BG_DGREY)
  29. ahead=$(_CC $YELLOW $BG_DGREY)
  30. behind=$(_CC $YELLOW $BG_DGREY)
  31. staged=$(_CC $CYAN $BG_DGREY)
  32. dirty=$(_CC $RED $BG_DGREY)
  33. diverged=$(_CC $RED $BG_DGREY)
  34. branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
  35. if [[ -n "$branch" ]]; then
  36. git_status=$(git status 2> /dev/null)
  37. # If nothing changes the color, we can spot unhandled cases.
  38. color=$unknown
  39. if [[ $git_status =~ 'Untracked files' ]]; then
  40. color=$untracked
  41. branch="${branch}?"
  42. fi
  43. if git stash show &>/dev/null; then
  44. color=$stash
  45. branch="${branch}+"
  46. fi
  47. if [[ $git_status =~ 'working directory clean' ]]; then
  48. color=$clean
  49. fi
  50. if [[ $git_status =~ 'Your branch is ahead' ]]; then
  51. color=$ahead
  52. branch="${branch}>"
  53. fi
  54. if [[ $git_status =~ 'Your branch is behind' ]]; then
  55. color=$behind
  56. branch="${branch}<"
  57. fi
  58. if [[ $git_status =~ 'Changes to be committed' ]]; then
  59. color=$staged
  60. fi
  61. if [[ $git_status =~ 'Changed but not updated' ||
  62. $git_status =~ 'Changes not staged' ||
  63. $git_status =~ 'Unmerged paths' ]]; then
  64. color=$dirty
  65. fi
  66. if [[ $git_status =~ 'Your branch'.+diverged ]]; then
  67. color=$diverged
  68. branch="${branch}!"
  69. fi
  70. echo -n "${color}${symbols[git]}${branch}"
  71. fi
  72. }
  73. set_prompt() {
  74. local lec="$?"
  75. if [ $COLOR_PROMPT = yes ]; then
  76. if [ $lec -ne 0 ]; then
  77. smilie="$(_CC $RED $BG_DGREY)${symbols[frownie]}"
  78. else
  79. smilie="$(_CC $GREEN $BG_DGREY)${symbols[smilie]}"
  80. fi
  81. PS1="${debian_chroot:+($debian_chroot)}$(_CC $GREEN $BG_DGREY)\u $(_CC $LBLUE $BG_DGREY)\w$(_CC $DEFAULT $BG_DGREY)|${smilie}$(_CC $DEFAULT $BG_DGREY)|$(_git_status)${NORMAL}$(_CFG $DGREY)${symbols[hard_separator]}${NORMAL} "
  82. else
  83. PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
  84. fi
  85. }
  86. PROMPT_COMMAND="set_prompt"