-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscmprompt.sh
executable file
·124 lines (106 loc) · 3.55 KB
/
scmprompt.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
SELF=$(readlink -f ${BASH_SOURCE[0]})
if [ "x$__SCM_PROMPT_DIR" == "x" ]
then
__SCM_PROMPT_DIR=$(dirname $SELF)
fi
function update_current_SCM_vars() {
unset __CURRENT_SCM_STATUS
local scmstatus="${__SCM_PROMPT_DIR}/scmstatus.py"
_SCM_STATUS=$(python $scmstatus)
__CURRENT_SCM_STATUS=($_SCM_STATUS)
SCM_TYPE=${__CURRENT_SCM_STATUS[0]}
SCM_BRANCH=${__CURRENT_SCM_STATUS[1]}
SCM_REMOTE=${__CURRENT_SCM_STATUS[2]}
if [[ "." == "$SCM_REMOTE" ]]; then
unset SCM_REMOTE
fi
SCM_STAGED=${__CURRENT_SCM_STATUS[3]}
SCM_CONFLICTS=${__CURRENT_SCM_STATUS[4]}
SCM_CHANGED=${__CURRENT_SCM_STATUS[5]}
SCM_UNTRACKED=${__CURRENT_SCM_STATUS[6]}
SCM_CLEAN=${__CURRENT_SCM_STATUS[7]}
}
function setScmPrompt() {
local exit_code=$?
# Colors
# Reset
local ResetColor="\[\033[0m\]" # Text Reset
# Regular Colors
local Red="\[\033[0;31m\]" # Red
local Yellow="\[\033[0;33m\]" # Yellow
local Blue="\[\033[0;34m\]" # Blue
local WHITE='\[\033[37m\]'
# Bold
local BGreen="\[\033[1;32m\]" # Green
# High Intensty
local IBlack="\[\033[0;90m\]" # Black
# Bold High Intensty
local Magenta="\[\033[1;95m\]" # Purple
# Various variables you might want for your PS1 prompt instead
local Time12a="\@"
local PathShort="\w"
local Hostname="\H"
local Username="\u"
# Default values for the appearance of the prompt. Configure at will.
local SCM_PROMPT_PREFIX="["
local SCM_PROMPT_SUFFIX="]"
local SCM_PROMPT_SEPARATOR="|"
local SCM_PROMPT_BRANCH="${Magenta}"
local SCM_PROMPT_STAGED="${Red}● "
local SCM_PROMPT_CONFLICTS="${Red}✖ "
local SCM_PROMPT_CHANGED="${Blue}✚ "
local SCM_PROMPT_REMOTE=" "
local SCM_PROMPT_UNTRACKED="…"
local SCM_PROMPT_CLEAN="${BGreen}✔"
unset PROMPT_START
unset PROMPT_END
if [[ $EUID -ne 0 ]]; then
local _USER="$BGreen$Username$ResetColor"
else
local _USER="$Red$Username$ResetColor"
fi
PROMPT_START="$_USER@$Yellow$Hostname $Blue$PathShort$ResetColor"
PROMPT_END=" $WHITE$Time12a$ResetColor\\$ "
if [ $exit_code -eq 0 ]; then
exit_code="$BGreen$exit_code$ResetColor"
else
exit_code="$Red$exit_code$ResetColor"
fi
update_current_SCM_vars
set_virtualenv
if [ -n "$__CURRENT_SCM_STATUS" ]; then
STATUS=" ${Yellow}$SCM_TYPE$ResetColor $SCM_PROMPT_PREFIX$SCM_PROMPT_BRANCH$SCM_BRANCH$ResetColor"
if [ -n "$SCM_REMOTE" ]; then
STATUS="$STATUS$SCM_PROMPT_REMOTE$SCM_REMOTE$ResetColor"
fi
STATUS="$STATUS$SCM_PROMPT_SEPARATOR"
if [ "$SCM_STAGED" -ne "0" ]; then
STATUS="$STATUS$SCM_PROMPT_STAGED$SCM_STAGED$ResetColor"
fi
if [ "$SCM_CONFLICTS" -ne "0" ]; then
STATUS="$STATUS$SCM_PROMPT_CONFLICTS$SCM_CONFLICTS$ResetColor"
fi
if [ "$SCM_CHANGED" -ne "0" ]; then
STATUS="$STATUS$SCM_PROMPT_CHANGED$SCM_CHANGED$ResetColor"
fi
if [ "$SCM_UNTRACKED" -ne "0" ]; then
STATUS="$STATUS$SCM_PROMPT_UNTRACKED$SCM_UNTRACKED$ResetColor"
fi
if [ "$SCM_CLEAN" -eq "1" ]; then
STATUS="$STATUS$SCM_PROMPT_CLEAN"
fi
STATUS="$STATUS$ResetColor$SCM_PROMPT_SUFFIX"
PS1="[$exit_code] $PYTHON_VIRTUALENV$PROMPT_START$STATUS$PROMPT_END"
else
PS1="[$exit_code] $PROMPT_START$PROMPT_END"
fi
}
# Determine active Python virtualenv details.
function set_virtualenv () {
if test -z "$VIRTUAL_ENV" ; then
PYTHON_VIRTUALENV=""
else
PYTHON_VIRTUALENV="${BLUE}(`basename \"$VIRTUAL_ENV\"`)${ResetColor} "
fi
}
PROMPT_COMMAND=setScmPrompt