-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.custom-prompt
62 lines (52 loc) · 1.53 KB
/
.custom-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
declare -A colors=(
["red"]="31"
["green"]="32"
["yellow"]="33"
["blue"]="34"
["cyan"]="36"
["white"]="37"
["reset"]="00"
)
c() {
local bold=
[ "${2}" = bold ] && bold="01;"
echo -e "\033[${bold}${colors["$1"]}m"
}
pc() {
local bold=
[ "${2}" = bold ] && bold="01;"
echo "\[\033[${bold}${colors["$1"]}m\]"
}
parse_git_repo() {
local repo stashc
if git rev-parse --git-dir >/dev/null 2>&1; then
stashc="$(git stash list 2>/dev/null | wc -l | xargs)"
if [ ${stashc} = 0 ]; then
stashc=
else
stashc=" [#${stashc}]"
fi
repo="$(git branch 2>/dev/null | sed -n '/^\*/s/^\* //p')"
if git diff --ignore-submodules=dirty --exit-code --quiet 2>/dev/null >&2; then
if git diff --ignore-submodules=dirty --exit-code --cached --quiet 2>/dev/null >&2; then
repo="$(pc green)${repo}$(pc reset)"
else
repo="$(pc cyan)"'!'"${repo}$(pc reset)"
fi
else
repo="$(pc red)"'!'"${repo}$(pc reset)"
fi
echo " ${repo}${stashc}"
fi
}
prompt_command() {
PS1="$(pc blue bold) \w$(pc reset)$(parse_git_repo) $(pc blue bold)\$$(pc reset) "
if [ -n "${VIRTUAL_ENV}" ]; then
PS1="$(pc white bold)($(basename "${VIRTUAL_ENV}"))$(pc reset)${PS1}"
fi
if [ -n "${AWSUME_PROFILE}" ]; then
PS1="$(pc yellow bold)[$(basename "${AWSUME_PROFILE}")]$(pc reset)${PS1}"
fi
}
PROMPT_COMMAND=prompt_command
PROMPT_DIRTRIM=3