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.

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