forked from magicmonty/bash-git-prompt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitprompt.sh
95 lines (77 loc) · 2.44 KB
/
gitprompt.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
__GIT_PROMPT_DIR=~/.bash
# Colors
# Reset
ResetColor="\[\033[0m\]" # Text Reset
# Regular Colors
Red="\[\033[0;31m\]" # Red
Yellow="\[\033[0;33m\]" # Yellow
Blue="\[\033[0;34m\]" # Blue
LGray="\[\033[0;37m\]" # Light Gray
# Bold
BGreen="\[\033[1;32m\]" # Green
# High Intensty
IBlack="\[\033[0;90m\]" # Black
# Bold High Intensty
Magenta="\[\033[1;95m\]" # Purple
# Various variables you might want for your PS1 prompt instead
Time24="\T "
PathShort="\w"
# Default values for the appearance of the prompt. Configure at will.
GIT_PROMPT_PREFIX="("
GIT_PROMPT_SUFFIX=")"
GIT_PROMPT_SEPARATOR="|"
GIT_PROMPT_BRANCH="${Magenta}"
GIT_PROMPT_STAGED="${Red}● "
GIT_PROMPT_CONFLICTS="${Red}✖ "
GIT_PROMPT_CHANGED="${Blue}✚ "
GIT_PROMPT_REMOTE=" "
GIT_PROMPT_UNTRACKED="…"
GIT_PROMPT_CLEAN="${BGreen}✔"
PROMPT_START="$LGray$Time24$ResetColor$Yellow$PathShort$ResetColor"
PROMPT_END=" \$ "
function update_current_git_vars() {
unset __CURRENT_GIT_STATUS
local gitstatus="${__GIT_PROMPT_DIR}/gitstatus.py"
_GIT_STATUS=$(python $gitstatus)
__CURRENT_GIT_STATUS=($_GIT_STATUS)
GIT_BRANCH=${__CURRENT_GIT_STATUS[0]}
GIT_REMOTE=${__CURRENT_GIT_STATUS[1]}
if [[ "." == "$GIT_REMOTE" ]]; then
unset GIT_REMOTE
fi
GIT_STAGED=${__CURRENT_GIT_STATUS[2]}
GIT_CONFLICTS=${__CURRENT_GIT_STATUS[3]}
GIT_CHANGED=${__CURRENT_GIT_STATUS[4]}
GIT_UNTRACKED=${__CURRENT_GIT_STATUS[5]}
GIT_CLEAN=${__CURRENT_GIT_STATUS[6]}
}
function setGitPrompt() {
update_current_git_vars
if [ -n "$__CURRENT_GIT_STATUS" ]; then
STATUS=" $GIT_PROMPT_PREFIX$GIT_PROMPT_BRANCH$GIT_BRANCH$ResetColor"
if [ -n "$GIT_REMOTE" ]; then
STATUS="$STATUS$GIT_PROMPT_REMOTE$GIT_REMOTE$ResetColor"
fi
STATUS="$STATUS$GIT_PROMPT_SEPARATOR"
if [ "$GIT_STAGED" -ne "0" ]; then
STATUS="$STATUS$GIT_PROMPT_STAGED$GIT_STAGED$ResetColor"
fi
if [ "$GIT_CONFLICTS" -ne "0" ]; then
STATUS="$STATUS$GIT_PROMPT_CONFLICTS$GIT_CONFLICTS$ResetColor"
fi
if [ "$GIT_CHANGED" -ne "0" ]; then
STATUS="$STATUS$GIT_PROMPT_CHANGED$GIT_CHANGED$ResetColor"
fi
if [ "$GIT_UNTRACKED" -ne "0" ]; then
STATUS="$STATUS$GIT_PROMPT_UNTRACKED$GIT_UNTRACKED$ResetColor"
fi
if [ "$GIT_CLEAN" -eq "1" ]; then
STATUS="$STATUS$GIT_PROMPT_CLEAN"
fi
STATUS="$STATUS$ResetColor$GIT_PROMPT_SUFFIX"
PS1="$PROMPT_START$STATUS$PROMPT_END"
else
PS1="$PROMPT_START$PROMPT_END"
fi
}
PROMPT_COMMAND=setGitPrompt