-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.sh
78 lines (66 loc) · 2.26 KB
/
prompt.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
function __prompt() {
local -r last_exit_code=$?
local -r use_color="$1"
local -r show_host="${2:-no}"
local -r C_NONE='\[\e[00m\]'
local -r C_RED='\[\e[31m\]'
local -r C_GREEN='\[\e[32m\]'
local -r C_YELLOW='\[\e[33m\]'
local -r C_CYAN='\[\e[36m\]'
local -r C_WHITE='\[\e[37m\]'
local -r C_BOLD_RED='\[\e[01;31m\]'
local -r C_BOLD_GREEN='\[\e[01;32m\]'
local -r C_BOLD_YELLOW='\[\e[01;33m\]'
local -r C_BOLD_PURPLE='\[\e[01;35m\]'
local -r C_BOLD_CYAN='\[\e[01;36m\]'
if [ "$UID" = 0 ]; then
local -r C_USER=$C_RED
local -r C_HOST=$C_BOLD_CYAN
else
local -r C_USER=$C_CYAN
local -r C_HOST=$C_BOLD_GREEN
fi
local git_prompt=''
if git rev-parse --git-dir >/dev/null 2>&1; then
local git_untracked_files=''
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
git_untracked_files='*'
fi
if [ "$use_color" = 'yes' ]; then
local git_color=$C_GREEN
if ! git diff --quiet; then
git_color=$C_RED
elif ! git diff --cached --quiet; then
git_color=$C_YELLOW
fi
git_prompt="[${git_color}\$(__git_ps1 \"%s\")${C_NONE}${git_untracked_files}]"
else
git_prompt="[\$(__git_ps1 \"%s\")${git_untracked_files}]"
fi
fi
local hostname='\h'
if [ "$show_host" = 'full' ]; then
hostname='\H'
fi
local host=''
if [ "$show_host" != 'no' ]; then
if [ "$use_color" = 'yes' ]; then
host="${C_YELLOW}@${C_BOLD_RED}<${C_HOST}${hostname}${C_BOLD_RED}>${C_NONE}"
else
host="@!${hostname}!"
fi
fi
local error_mark=''
if [ "$last_exit_code" -ne 0 ]; then
if [ "$use_color" = 'yes' ]; then
error_mark="${C_BOLD_RED}!${C_NONE}"
else
error_mark='!'
fi
fi
if [ "$use_color" = 'yes' ]; then
PS1="╭─${C_WHITE}\t${C_NONE} \${debian_chroot:+(\$debian_chroot)}${C_USER}\u${C_NONE}${host}: ${C_BOLD_YELLOW}\w${C_NONE}${git_prompt}\n╰─${error_mark}${C_BOLD_PURPLE}\$${C_NONE} "
else
PS1="╭─\t \${debian_chroot:+(\$debian_chroot)}\u${host}: \w${git_prompt}\n╰─${error_mark}\$ "
fi
}