A bin folder, holding helpfull scripts and commands
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

giti 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. #
  3. #
  4. # command line arguments
  5. #
  6. usage="Usage: $0 [-p | output for prompt]"
  7. while getopts "hp" options; do
  8. case $options in
  9. p ) PROMPT="True";;
  10. h ) echo $usage
  11. exit 0
  12. ;;
  13. \? ) echo $usage
  14. exit 1
  15. ;;
  16. esac
  17. done
  18. #
  19. # color definitions
  20. #
  21. COLOR_WHITE="\033[00m"
  22. COLOR_CYAN="\033[1;36m"
  23. COLOR_RED="\033[1;31m"
  24. COLOR_YELLOW="\033[1;33m"
  25. COLOR_DARKYELLOW="\033[0;33m"
  26. COLOR_GREEN="\033[1;32m"
  27. COLOR_DARKGREEN="\033[0;32m"
  28. COLOR_OCHRE="\033[38;5;95m"
  29. #
  30. # git information storage
  31. #
  32. git_status="$(LANGUAGE='en_US.UTF-8 git' git status 2> /dev/null)"
  33. git_diff="$(git status --porcelain 2> /dev/null)"
  34. #
  35. # decision for git output (path is repository)
  36. #
  37. if [ -z "$git_status" ]; then
  38. # No GIT repository
  39. exit
  40. fi
  41. #
  42. # git preparations
  43. #
  44. git_branch="$(git branch 2> /dev/null | sed --quiet 's/* \(.*\)/\1/p')"
  45. git_url="$(git config --get remote.origin.url 2> /dev/null)"
  46. if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
  47. git_status_color="$COLOR_RED"
  48. git_status_text="local changes"
  49. elif [[ $git_status =~ "Your branch is behind" ]]; then
  50. git_status_color="$COLOR_YELLOW"
  51. git_status_text="pull required"
  52. elif [[ $git_status =~ "Your branch is ahead of" ]]; then
  53. git_status_color="$COLOR_YELLOW"
  54. git_status_text="push required"
  55. elif [[ $git_status =~ "nothing to commit" ]]; then
  56. git_status_color="$COLOR_DARKGREEN"
  57. git_status_text="clean "
  58. else
  59. git_status_color="$COLOR_OCHRE"
  60. git_status_text="unknown "
  61. fi
  62. #
  63. # Start of console output
  64. #
  65. ## STATUS AND INFO ######
  66. if [[ $PROMPT ]]; then
  67. # print status
  68. echo -e "$git_status_color├──$COLOR_GREEN($git_branch)$git_status_color - $git_status_text - $COLOR_CYAN$git_url$COLOR_WHITE"
  69. else
  70. # print status and
  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 == "" ]]; then
  74. echo -e "$git_status_color├────────────────────────────────────────────────────────────────────────────────────"
  75. else
  76. echo -e "$git_status_color└────────────────────────────────────────────────────────────────────────────────────$COLOR_WHITE\n \b"
  77. fi
  78. fi
  79. ## FILE INFO ############
  80. if [[ ! $git_diff == "" ]]; then
  81. if [[ ! $PROMPT || "$GIT_PROMPT_DETAILS" == "on" ]]; then
  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. fi
  92. ## CLOSING ##############
  93. if [[ $PROMPT ]]; then
  94. echo -e " \b"
  95. else
  96. echo -e "$git_status_color└────────────────────────────────────────────────────────────────────────────────────$COLOR_WHITE\n \b"
  97. fi