2020-01-26 17:28:29 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2023-09-30 09:17:25 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# command line arguments
|
|
|
|
#
|
|
|
|
usage="Usage: $0 [-p | output for prompt]"
|
|
|
|
while getopts "hp" options; do
|
2020-01-26 17:28:29 +01:00
|
|
|
case $options in
|
2023-09-30 09:17:25 +02:00
|
|
|
p ) PROMPT="True";;
|
2020-01-26 17:28:29 +01:00
|
|
|
h ) echo $usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
\? ) echo $usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-09-30 09:17:25 +02:00
|
|
|
#
|
|
|
|
# color definitions
|
|
|
|
#
|
|
|
|
COLOR_WHITE="\033[00m"
|
|
|
|
COLOR_CYAN="\033[1;36m"
|
|
|
|
COLOR_RED="\033[1;31m"
|
|
|
|
COLOR_YELLOW="\033[1;33m"
|
|
|
|
COLOR_DARKYELLOW="\033[0;33m"
|
|
|
|
COLOR_GREEN="\033[1;32m"
|
|
|
|
COLOR_DARKGREEN="\033[0;32m"
|
|
|
|
COLOR_OCHRE="\033[38;5;95m"
|
|
|
|
|
|
|
|
#
|
|
|
|
# git information storage
|
|
|
|
#
|
|
|
|
git_status="$(LANGUAGE='en_US.UTF-8 git' git status 2> /dev/null)"
|
|
|
|
git_diff="$(git status --porcelain 2> /dev/null)"
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# decision for git output (path is repository)
|
|
|
|
#
|
|
|
|
if [ -z "$git_status" ]; then
|
|
|
|
# No GIT repository
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
#
|
|
|
|
# git preparations
|
|
|
|
#
|
|
|
|
git_branch="$(git branch 2> /dev/null | sed --quiet 's/* \(.*\)/\1/p')"
|
|
|
|
git_url="$(git config --get remote.origin.url 2> /dev/null)"
|
|
|
|
if [[ ! $git_status =~ "working tree clean" ]] && [[ ! $git_status =~ "working directory clean" ]]; then
|
|
|
|
git_status_color="$COLOR_RED"
|
|
|
|
git_status_text="local changes"
|
|
|
|
elif [[ $git_status =~ "Your branch is behind" ]]; then
|
|
|
|
git_status_color="$COLOR_YELLOW"
|
|
|
|
git_status_text="pull required"
|
|
|
|
elif [[ $git_status =~ "Your branch is ahead of" ]]; then
|
|
|
|
git_status_color="$COLOR_YELLOW"
|
|
|
|
git_status_text="push required"
|
|
|
|
elif [[ $git_status =~ "nothing to commit" ]]; then
|
|
|
|
git_status_color="$COLOR_DARKGREEN"
|
|
|
|
git_status_text="clean "
|
2020-01-26 17:28:29 +01:00
|
|
|
else
|
2023-09-30 09:17:25 +02:00
|
|
|
git_status_color="$COLOR_OCHRE"
|
|
|
|
git_status_text="unknown "
|
|
|
|
fi
|
|
|
|
|
2020-01-26 17:28:29 +01:00
|
|
|
|
2023-09-30 09:17:25 +02:00
|
|
|
#
|
|
|
|
# Start of console output
|
|
|
|
#
|
|
|
|
|
|
|
|
## STATUS AND INFO ######
|
|
|
|
if [[ $PROMPT ]]; then
|
|
|
|
# print status
|
|
|
|
echo -e "$git_status_color├──$COLOR_GREEN($git_branch)$git_status_color - $git_status_text - $COLOR_CYAN$git_url$COLOR_WHITE"
|
|
|
|
else
|
|
|
|
# print status and
|
|
|
|
echo -e "$git_status_color┌───┤ $git_status_text ├────────────────────────────────────────────────────────────────"
|
|
|
|
echo -e "$git_status_color│ $COLOR_GREEN($git_branch) $COLOR_CYAN$git_url"
|
|
|
|
|
|
|
|
if [[ ! $git_diff == "" ]]; then
|
|
|
|
echo -e "$git_status_color├────────────────────────────────────────────────────────────────────────────────────"
|
|
|
|
else
|
|
|
|
echo -e "$git_status_color└────────────────────────────────────────────────────────────────────────────────────$COLOR_WHITE\n \b"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
## FILE INFO ############
|
|
|
|
if [[ ! $git_diff == "" ]]; then
|
|
|
|
if [[ ! $PROMPT || "$GIT_PROMPT_DETAILS" == "on" ]]; then
|
|
|
|
IFS=$'\n'
|
|
|
|
for ENTRY in $git_diff; do
|
2023-09-30 09:22:11 +02:00
|
|
|
if [[ $ENTRY = "D "* ]] || [[ $ENTRY = "A "* ]] || [[ $ENTRY = "M "* ]] || [[ $ENTRY = "MM"* ]] || [[ $ENTRY = "R "* ]]; then
|
2023-09-30 09:17:25 +02:00
|
|
|
echo -e "$git_status_color│ $COLOR_DARKYELLOW$ENTRY"
|
|
|
|
else
|
|
|
|
echo -e "$git_status_color│ $COLOR_YELLOW$ENTRY"
|
2023-06-17 14:26:03 +00:00
|
|
|
fi
|
2023-09-30 09:17:25 +02:00
|
|
|
done
|
2023-06-17 14:26:03 +00:00
|
|
|
fi
|
2020-01-26 17:28:29 +01:00
|
|
|
fi
|
2023-09-30 09:17:25 +02:00
|
|
|
|
|
|
|
## CLOSING ##############
|
|
|
|
if [[ $PROMPT ]]; then
|
|
|
|
echo -e " \b"
|
|
|
|
else
|
|
|
|
echo -e "$git_status_color└────────────────────────────────────────────────────────────────────────────────────$COLOR_WHITE\n \b"
|
|
|
|
fi
|