A bin folder, holding helpfull scripts and commands
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

giti 3.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 [[ $SHORT ]]; then
  33. if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
  34. git_status_color="$COLOR_RED"
  35. git_status_text="local changes"
  36. elif [[ $git_status =~ "Your branch is behind" ]]; then
  37. git_status_color="$COLOR_YELLOW"
  38. git_status_text="pull required"
  39. elif [[ $git_status =~ "Your branch is ahead of" ]]; then
  40. git_status_color="$COLOR_YELLOW"
  41. git_status_text="push required"
  42. elif [[ $git_status =~ "nothing to commit" ]]; then
  43. git_status_color="$COLOR_DARKGREEN"
  44. git_status_text="clean "
  45. else
  46. git_status_color="$COLOR_OCHRE"
  47. git_status_text="unknown "
  48. fi
  49. echo -ne "$git_status_color$git_status_text$COLOR_WHITE"
  50. else
  51. if [[ ! $git_status = "" ]]; then
  52. git_branch="$(git branch 2> /dev/null | sed --quiet 's/* \(.*\)/\1/p')"
  53. git_url="$(git config --get remote.origin.url 2> /dev/null)"
  54. if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
  55. git_status_color="$COLOR_RED"
  56. git_status_text="╡ local changes ╞"
  57. elif [[ $git_status =~ "Your branch is behind" ]]; then
  58. git_status_color="$COLOR_YELLOW"
  59. git_status_text="╡ pull required ╞"
  60. elif [[ $git_status =~ "Your branch is ahead of" ]]; then
  61. git_status_color="$COLOR_YELLOW"
  62. git_status_text="╡ push required ╞"
  63. elif [[ $git_status =~ "nothing to commit" ]]; then
  64. git_status_color="$COLOR_DARKGREEN"
  65. git_status_text="╡ clean ╞════════"
  66. else
  67. git_status_color="$COLOR_OCHRE"
  68. git_status_text="╡ unknown ╞══════"
  69. fi
  70. fi
  71. echo -e "$git_status_color╔═══$git_status_text════════════════════════════════════════════════════════════════"
  72. echo -e "$git_status_color║ $COLOR_GREEN($git_branch) $COLOR_CYAN$git_url"
  73. if [[ ! $git_diff == "" && $NO_DETAILS != "True" ]]; then
  74. echo -e "$git_status_color╠════════════════════════════════════════════════════════════════════════════════════"
  75. IFS=$'\n'
  76. for ENTRY in $git_diff; do
  77. if [[ $ENTRY = "D "* ]] || [[ $ENTRY = "A "* ]] || [[ $ENTRY = "M "* ]] || [[ $ENTRY = "R "* ]]; then
  78. echo -e "$git_status_color║ $COLOR_DARKYELLOW$ENTRY"
  79. else
  80. echo -e "$git_status_color║ $COLOR_YELLOW$ENTRY"
  81. fi
  82. done
  83. fi
  84. echo -e "$git_status_color╚════════════════════════════════════════════════════════════════════════════════════$COLOR_WHITE\n \b"
  85. fi
  86. fi