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