A bin folder, holding helpfull scripts and commands
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. #
  3. usage="Usage: $0 [-n | no details] [-r | repeat]"
  4. while getopts "hnrs" options; do
  5. case $options in
  6. n ) NO_DETAILS="True";;
  7. r ) REPEAT="True";;
  8. s ) SHORT="True";;
  9. h ) echo $usage
  10. exit 0
  11. ;;
  12. \? ) echo $usage
  13. exit 1
  14. ;;
  15. esac
  16. done
  17. if [[ $REPEAT == "True" ]]; then
  18. watch -n 1 -c "clear && $0 -s"
  19. else
  20. COLOR_WHITE="\033[00m"
  21. COLOR_CYAN="\033[1;36m"
  22. COLOR_RED="\033[1;31m"
  23. COLOR_YELLOW="\033[1;33m"
  24. COLOR_DARKYELLOW="\033[0;33m"
  25. COLOR_GREEN="\033[1;32m"
  26. COLOR_DARKGREEN="\033[0;32m"
  27. COLOR_OCHRE="\033[38;5;95m"
  28. #
  29. git_status="$(LANGUAGE='en_US.UTF-8 git' git status 2> /dev/null)"
  30. git_diff="$(git status --porcelain 2> /dev/null)"
  31. #
  32. if [ -z "$git_status" ]; then
  33. # No GIT repository
  34. exit
  35. fi
  36. if [[ $SHORT ]]; then
  37. if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
  38. git_status_color="$COLOR_RED"
  39. git_status_text="local changes"
  40. elif [[ $git_status =~ "Your branch is behind" ]]; then
  41. git_status_color="$COLOR_YELLOW"
  42. git_status_text="pull required"
  43. elif [[ $git_status =~ "Your branch is ahead of" ]]; then
  44. git_status_color="$COLOR_YELLOW"
  45. git_status_text="push required"
  46. elif [[ $git_status =~ "nothing to commit" ]]; then
  47. git_status_color="$COLOR_DARKGREEN"
  48. git_status_text="clean "
  49. else
  50. git_status_color="$COLOR_OCHRE"
  51. git_status_text="unknown "
  52. fi
  53. echo -ne "$git_status_color$git_status_text$COLOR_WHITE"
  54. else
  55. if [[ ! $git_status = "" ]]; then
  56. git_branch="$(git branch 2> /dev/null | sed --quiet 's/* \(.*\)/\1/p')"
  57. git_url="$(git config --get remote.origin.url 2> /dev/null)"
  58. if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
  59. git_status_color="$COLOR_RED"
  60. git_status_text="local changes"
  61. elif [[ $git_status =~ "Your branch is behind" ]]; then
  62. git_status_color="$COLOR_YELLOW"
  63. git_status_text="pull required"
  64. elif [[ $git_status =~ "Your branch is ahead of" ]]; then
  65. git_status_color="$COLOR_YELLOW"
  66. git_status_text="push required"
  67. elif [[ $git_status =~ "nothing to commit" ]]; then
  68. git_status_color="$COLOR_DARKGREEN"
  69. git_status_text="clean "
  70. else
  71. git_status_color="$COLOR_OCHRE"
  72. git_status_text="unknown "
  73. fi
  74. fi
  75. if [[ $NO_DETAILS ]]; then
  76. # echo -e "$git_status_color╠══$COLOR_GREEN($git_branch)$git_status_color - $git_status_text - $COLOR_CYAN$git_url$COLOR_WHITE\n\b"
  77. echo -e "$git_status_color├──$COLOR_GREEN($git_branch)$git_status_color - $git_status_text - $COLOR_CYAN$git_url$COLOR_WHITE\n\b"
  78. else
  79. # echo -e "$git_status_color╔═══╡ $git_status_text ╞════════════════════════════════════════════════════════════════"
  80. echo -e "$git_status_color┌───┤ $git_status_text ├────────────────────────────────────────────────────────────────"
  81. # echo -e "$git_status_color║ $COLOR_GREEN($git_branch) $COLOR_CYAN$git_url"
  82. echo -e "$git_status_color│ $COLOR_GREEN($git_branch) $COLOR_CYAN$git_url"
  83. if [[ ! $git_diff == "" ]]; then
  84. # echo -e "$git_status_color╠════════════════════════════════════════════════════════════════════════════════════"
  85. echo -e "$git_status_color├────────────────────────────────────────────────────────────────────────────────────"
  86. IFS=$'\n'
  87. for ENTRY in $git_diff; do
  88. if [[ $ENTRY = "D "* ]] || [[ $ENTRY = "A "* ]] || [[ $ENTRY = "M "* ]] || [[ $ENTRY = "R "* ]]; then
  89. # echo -e "$git_status_color║ $COLOR_DARKYELLOW$ENTRY"
  90. echo -e "$git_status_color│ $COLOR_DARKYELLOW$ENTRY"
  91. else
  92. # echo -e "$git_status_color║ $COLOR_YELLOW$ENTRY"
  93. echo -e "$git_status_color│ $COLOR_YELLOW$ENTRY"
  94. fi
  95. done
  96. fi
  97. # echo -e "$git_status_color╚════════════════════════════════════════════════════════════════════════════════════$COLOR_WHITE\n \b"
  98. echo -e "$git_status_color└────────────────────────────────────────────────────────────────────────────────────$COLOR_WHITE\n \b"
  99. fi
  100. fi
  101. fi