1
1
# shellcheck shell=bash
2
2
# shellcheck disable=SC2034 # Expected behavior for themes.
3
- # shellcheck disable=SC2154 #TODO: fix these all.
4
3
5
4
# Detect whether a reboot is required
6
5
function show_reboot_required() {
7
- if [ -n " $_bf_prompt_reboot_info " ]; then
8
- if [ -f /var/run/reboot-required ]; then
9
- printf " Reboot required!"
6
+ if [[ -n " ${ _bf_prompt_reboot_info} " ] ]; then
7
+ if [[ -f /var/run/reboot-required ] ]; then
8
+ printf ' %s ' " Reboot required!"
10
9
fi
11
10
fi
12
11
}
13
12
14
13
# Set different host color for local and remote sessions
15
14
function set_host_color() {
16
15
# Detect if connection is through SSH
17
- if [[ -n $ SSH_CLIENT ]]; then
18
- printf ' %s' " ${lime_yellow} "
16
+ if [[ -n " ${ SSH_CLIENT:- } " ]]; then
17
+ printf ' %s' " ${lime_yellow? } "
19
18
else
20
- printf ' %s' " ${light_orange} "
19
+ printf ' %s' " ${light_orange? } "
21
20
fi
22
21
}
23
22
24
23
# Set different username color for users and root
25
24
function set_user_color() {
26
- case $( id -u ) in
25
+ case ${EUID :- $UID } in
27
26
0)
28
- printf ' %s' " ${red} "
27
+ printf ' %s' " ${red? } "
29
28
;;
30
29
* )
31
- printf ' %s' " ${cyan} "
30
+ printf ' %s' " ${cyan? } "
32
31
;;
33
32
esac
34
33
}
@@ -47,40 +46,48 @@ function set_custom_colors() {
47
46
powder_blue=" \[$( tput setaf 153) \]"
48
47
}
49
48
50
- __ps_time () {
51
- printf ' %s' " $( clock_prompt) ${normal} \n"
49
+ function __ps_time() {
50
+ local clock_prompt
51
+ clock_prompt=" $( clock_prompt) "
52
+ printf ' %s\n' " ${clock_prompt}${normal?} "
52
53
}
53
54
54
55
function prompt_command() {
55
- ps_reboot=" ${bright_yellow} $( show_reboot_required) ${normal} \n"
56
+ local show_reboot_required set_user_color set_host_color scm_prompt ps_time
57
+ show_reboot_required=" $( show_reboot_required) "
58
+ ps_reboot=" ${bright_yellow?}${show_reboot_required}${normal?} \n"
56
59
57
- ps_username=" $( set_user_color) \u${normal} "
58
- ps_uh_separator=" ${dark_grey} @${normal} "
59
- ps_hostname=" $( set_host_color) \h${normal} "
60
+ set_user_color=" $( set_user_color) "
61
+ ps_username=" ${set_user_color} \u${normal} "
62
+ ps_uh_separator=" ${dark_grey?} @${normal} "
63
+ set_host_color=" $( set_host_color) "
64
+ ps_hostname=" ${set_host_color} \h${normal} "
60
65
61
- ps_path=" ${yellow} \w${normal} "
62
- ps_scm_prompt=" ${light_grey} $( scm_prompt) "
66
+ ps_path=" ${yellow?} \w${normal} "
67
+ scm_prompt=" $( scm_prompt) "
68
+ ps_scm_prompt=" ${light_grey?}${scm_prompt} "
63
69
64
70
ps_user_mark=" ${normal} ${normal} "
65
71
ps_user_input=" ${normal} "
66
72
67
73
# Set prompt
68
- PS1=" $ps_reboot $( __ps_time) $ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input "
74
+ ps_time=" $( __ps_time) "
75
+ PS1=" $ps_reboot ${ps_time} $ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input "
69
76
}
70
77
71
78
# Initialize custom colors
72
79
set_custom_colors
73
80
74
- THEME_CLOCK_COLOR= ${THEME_CLOCK_COLOR:- " $dark_grey " }
81
+ : " ${THEME_CLOCK_COLOR:= " $dark_grey " } "
75
82
76
83
# scm theming
77
84
SCM_THEME_PROMPT_PREFIX=" "
78
85
SCM_THEME_PROMPT_SUFFIX=" "
79
86
80
- SCM_THEME_PROMPT_DIRTY=" ${bold_red} ✗${light_grey} "
81
- SCM_THEME_PROMPT_CLEAN=" ${green} ✓${light_grey} "
82
- SCM_GIT_CHAR=" ${green} ±${light_grey} "
83
- SCM_SVN_CHAR=" ${bold_cyan} ⑆${light_grey} "
84
- SCM_HG_CHAR=" ${bold_red} ☿${light_grey} "
87
+ SCM_THEME_PROMPT_DIRTY=" ${bold_red? } ✗${light_grey? } "
88
+ SCM_THEME_PROMPT_CLEAN=" ${green? } ✓${light_grey? } "
89
+ SCM_GIT_CHAR=" ${green? } ±${light_grey? } "
90
+ SCM_SVN_CHAR=" ${bold_cyan? } ⑆${light_grey? } "
91
+ SCM_HG_CHAR=" ${bold_red? } ☿${light_grey? } "
85
92
86
93
safe_append_prompt_command prompt_command
0 commit comments