-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_prompt
61 lines (54 loc) · 1.67 KB
/
git_prompt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/env bash
git_info() {
# colors
local RESET="\033[0m"
local GRAY="\033[0;37m"
local LIGHT_GRAY="\033[1;30m"
local RED="\033[1;31m"
local LIGHT_RED="\033[0;31m"
local GREEN="\033[1;32m"
local BLUE="\033[1;34m"
local PINK="\033[0;35m"
local CYAN="\033[1;36m"
local PURPLE="\033[0;35m"
local WHITE="\033[1;37m"
local BROWN="\033[0;33m"
local GOOD="✔"
local AHEAD="∆"
local BEHIND="∇"
local CHANGED="ϟ"
local DIVERGED=""
local UNTRACKED="ಠ_ಠ"
local LEFTP="\xE2\xA6\x97"
local RIGHTP="\xE2\xA6\x98"
local GITICON=""
local NEW_LINE="\n"
git_place() {
local place=$(git status 2> /dev/null | head -n2 | tail -n1)
if [[ $( echo $place | grep "Your branch is ahead of" ) != "" ]]; then
echo -e "$PINK$AHEAD"
elif [[ $( echo $place | grep "Your branch is behind" ) != "" ]]; then
echo -e "$BLUE$BEHIND"
elif [[ $( echo $place | grep "Your branch and .* have diverged" ) != "" ]]; then
echo -e "$CYAN$DIVERGED"
else
echo -e "$GREEN$GOOD"
fi
}
git_status() {
local status=$(git status 2> /dev/null | tail -n1)
if [[ $status != "nothing to commit, working tree clean" ]]; then
if [[ $status == 'nothing added to commit but untracked files present (use "git add" to track)' ]]; then
echo -e "$PURPLE$UNTRACKED"
else
echo -e "$RED$CHANGED"
fi
fi
}
local branch=$(git branch -v --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
if [[ $branch != "" ]]; then
info=($branch)
echo -e " $RED$GITICON $LIGHT_GRAY$LEFTP$PINK${info[1]}$LIGHT_GRAY$RIGHTP $BROWN${info[0]} $(git_place) $(git_status)$RESET"
echo " "
fi
}