A collection of scripts and configurations for Bash (and others)
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

74 lines
2.0KB

  1. _show_last_exit_smilie() {
  2. # If the exit status of the last run command was a 0 (success), show a smile, otherwise a frown
  3. exit_status=$?
  4. if [[ "$exit_status" -ne 0 ]]; then
  5. echo "${NORMAL}[${RED}:(${NORMAL}]"
  6. else
  7. echo "${NORMAL}[${GREEN}:)${NORMAL}]"
  8. fi
  9. }
  10. # 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
  11. _git_status() {
  12. local unknown untracked stash clean ahead behind staged dirty diverged
  13. unknown=$BLUE
  14. untracked=$GREEN
  15. stash=$GREEN
  16. clean=$GREEN
  17. ahead=$YELLOW
  18. behind=$YELLOW
  19. staged=$CYAN
  20. dirty=$RED
  21. diverged=$RED
  22. branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
  23. if [[ -n "$branch" ]]; then
  24. git_status=$(git status 2> /dev/null)
  25. # If nothing changes the color, we can spot unhandled cases.
  26. color=$unknown
  27. if [[ $git_status =~ 'Untracked files' ]]; then
  28. color=$untracked
  29. branch="${branch}?"
  30. fi
  31. if git stash show &>/dev/null; then
  32. color=$stash
  33. branch="${branch}+"
  34. fi
  35. if [[ $git_status =~ 'working directory clean' ]]; then
  36. color=$clean
  37. fi
  38. if [[ $git_status =~ 'Your branch is ahead' ]]; then
  39. color=$ahead
  40. branch="${branch}>"
  41. fi
  42. if [[ $git_status =~ 'Your branch is behind' ]]; then
  43. color=$behind
  44. branch="${branch}<"
  45. fi
  46. if [[ $git_status =~ 'Changes to be committed' ]]; then
  47. color=$staged
  48. fi
  49. if [[ $git_status =~ 'Changed but not updated' ||
  50. $git_status =~ 'Changes not staged' ||
  51. $git_status =~ 'Unmerged paths' ]]; then
  52. color=$dirty
  53. fi
  54. if [[ $git_status =~ 'Your branch'.+diverged ]]; then
  55. color=$diverged
  56. branch="${branch}!"
  57. fi
  58. echo -n "${NORMAL}|${color}${branch}${NORMAL}|"
  59. fi
  60. }
  61. set_prompt() {
  62. if [ $1 = yes ]; then
  63. echo -n "${debian_chroot:+($debian_chroot)}${GREEN}\u${NORMAL}[${BLUE}\w${NORMAL}]$(_show_last_exit_smilie)$(_git_status)\$ "
  64. else
  65. echo -n "${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
  66. fi
  67. }