-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_prompt
134 lines (112 loc) · 3.79 KB
/
bash_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
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
125
126
127
128
129
130
131
132
133
# vim: ft=sh
parse_git_dirty() {
[ -n "$(git status --porcelain 2> /dev/null)" ] && echo "*"
}
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \\(.*\\)/\\1$(parse_git_dirty)/"
}
parse_git_remote_tracking() {
git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD 2> /dev/null)" 2> /dev/null
}
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt
# Reset
OFF='\[\033[0m\]' # Text Reset
# Regular Colors
BLACK='\[\033[0;30m\]' # Black
RED='\[\033[0;31m\]' # Red
GREEN='\[\033[0;32m\]' # Green
YELLOW='\[\033[0;33m\]' # Yellow
BLUE='\[\033[0;34m\]' # Blue
PURPLE='\[\033[0;35m\]' # Purple
CYAN='\[\033[0;36m\]' # Cyan
WHITE='\[\033[0;37m\]' # White
# Bold
BOLD_BLACK='\[\033[1;30m\]' # Black
BOLD_RED='\[\033[1;31m\]' # Red
BOLD_GREEN='\[\033[1;32m\]' # Green
BOLD_YELLOW='\[\033[1;33m\]' # Yellow
BOLD_BLUE='\[\033[1;34m\]' # Blue
BOLD_PURPLE='\[\033[1;35m\]' # Purple
BOLD_CYAN='\[\033[1;36m\]' # Cyan
BOLD_WHITE='\[\033[1;37m\]' # White
# Underline
UNDERLINE_BLACK='\[\033[4;30m\]' # Black
UNDERLINE_RED='\[\033[4;31m\]' # Red
UNDERLINE_GREEN='\[\033[4;32m\]' # Green
UNDERLINE_YELLOW='\[\033[4;33m\]' # Yellow
UNDERLINE_BLUE='\[\033[4;34m\]' # Blue
UNDERLINE_PURPLE='\[\033[4;35m\]' # Purple
UNDERLINE_CYAN='\[\033[4;36m\]' # Cyan
UNDERLINE_WHITE='\[\033[4;37m\]' # White
# Background
BACKGROUND_BLACK='\[\033[40m\]' # Black
BACKGROUND_RED='\[\033[41m\]' # Red
BACKGROUND_GREEN='\[\033[42m\]' # Green
BACKGROUND_YELLOW='\[\033[43m\]' # Yellow
BACKGROUND_BLUE='\[\033[44m\]' # Blue
BACKGROUND_PURPLE='\[\033[45m\]' # Purple
BACKGROUND_CYAN='\[\033[46m\]' # Cyan
BACKGROUND_WHITE='\[\033[47m\]' # White
# High Intensity
INTENSITY_BLACK='\[\033[0;90m\]' # Black
INTENSITY_RED='\[\033[0;91m\]' # Red
INTENSITY_GREEN='\[\033[0;92m\]' # Green
INTENSITY_YELLOW='\[\033[0;93m\]' # Yellow
INTENSITY_BLUE='\[\033[0;94m\]' # Blue
INTENSITY_PURPLE='\[\033[0;95m\]' # Purple
INTENSITY_CYAN='\[\033[0;96m\]' # Cyan
INTENSITY_WHITE='\[\033[0;97m\]' # White
# Bold High Intensity
BIBLACK='\[\033[1;90m\]' # Black
BIRED='\[\033[1;91m\]' # Red
BIGREEN='\[\033[1;92m\]' # Green
BIYELLOW='\[\033[1;93m\]' # Yellow
BIBLUE='\[\033[1;94m\]' # Blue
BIPURPLE='\[\033[1;95m\]' # Purple
BICYAN='\[\033[1;96m\]' # Cyan
BIWHITE='\[\033[1;97m\]' # White
# High Intensity backgrounds
IBBLACK='\[\033[0;100m\]' # Black
IBRED='\[\033[0;101m\]' # Red
IBGREEN='\[\033[0;102m\]' # Green
IBYELLOW='\[\033[0;103m\]' # Yellow
IBBLUE='\[\033[0;104m\]' # Blue
IBPURPLE='\[\033[0;105m\]' # Purple
IBCYAN='\[\033[0;106m\]' # Cyan
IBWHITE='\[\033[0;107m\]' # White
# bash PS1 keywords
# \u The name of the logged-in user
# \h The hostname up to the first '.'
# \H The full hostname
# \n Newline
# \$ Shows a $ for a regular user or # for root user
# \\ A literal backslash "\" character
prompt_command() {
PS1="$OFF"
# screen detector
if [ -n "$STY" ]; then
PS1="${YELLOW[$STY]} "
fi
# git branch and status
if [ -n "$(parse_git_branch)" ]; then
PS1="$PS1$RED\$(parse_git_branch) "
fi
# git remote tracking
REMOTETRACKING="$(parse_git_remote_tracking)"
if [ -n "$REMOTETRACKING" ]; then
PS1="$PS1$YELLOW($REMOTETRACKING) "
fi
if [ -z "$DISABLE_USER_IN_PROMPT" ]; then
if [ "$(id -u)" -eq 0 ]; then
# root prompt
PS1="$PS1$BOLD_RED"
else
# normal user prompt
PS1="$PS1$GREEN"
fi
PS1="$PS1\\u@\\H$BOLD_BLUE \\w $YELLOW\$ $WHITE"
else
PS1="$PS1$BOLD_BLUE\\w $YELLOW\$ $WHITE"
fi
}
export PROMPT_COMMAND="prompt_command"