A bin folder, holding helpfull scripts and commands
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

giti 4.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. else
  78. echo -e "$git_status_color╔═══╡ $git_status_text ╞════════════════════════════════════════════════════════════════"
  79. echo -e "$git_status_color║ $COLOR_GREEN($git_branch) $COLOR_CYAN$git_url"
  80. if [[ ! $git_diff == "" ]]; then
  81. echo -e "$git_status_color╠════════════════════════════════════════════════════════════════════════════════════"
  82. IFS=$'\n'
  83. for ENTRY in $git_diff; do
  84. if [[ $ENTRY = "D "* ]] || [[ $ENTRY = "A "* ]] || [[ $ENTRY = "M "* ]] || [[ $ENTRY = "R "* ]]; then
  85. echo -e "$git_status_color║ $COLOR_DARKYELLOW$ENTRY"
  86. else
  87. echo -e "$git_status_color║ $COLOR_YELLOW$ENTRY"
  88. fi
  89. done
  90. fi
  91. echo -e "$git_status_color╚════════════════════════════════════════════════════════════════════════════════════$COLOR_WHITE\n \b"
  92. fi
  93. fi
  94. fi