A bin folder, holding helpfull scripts and commands
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

giti 3.9KB

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