Skip to content

Commit 750b97c

Browse files
committed
theme/binaryanomaly: SC2154
Handle all unbound parameters, even colors! Local some variables, &c
1 parent a098c25 commit 750b97c

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed
Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
# shellcheck shell=bash
22
# shellcheck disable=SC2034 # Expected behavior for themes.
3-
# shellcheck disable=SC2154 #TODO: fix these all.
43

54
# Detect whether a reboot is required
65
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!"
109
fi
1110
fi
1211
}
1312

1413
# Set different host color for local and remote sessions
1514
function set_host_color() {
1615
# 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?}"
1918
else
20-
printf '%s' "${light_orange}"
19+
printf '%s' "${light_orange?}"
2120
fi
2221
}
2322

2423
# Set different username color for users and root
2524
function set_user_color() {
26-
case $(id -u) in
25+
case ${EUID:-$UID} in
2726
0)
28-
printf '%s' "${red}"
27+
printf '%s' "${red?}"
2928
;;
3029
*)
31-
printf '%s' "${cyan}"
30+
printf '%s' "${cyan?}"
3231
;;
3332
esac
3433
}
@@ -47,40 +46,48 @@ function set_custom_colors() {
4746
powder_blue="\[$(tput setaf 153)\]"
4847
}
4948

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?}"
5253
}
5354

5455
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"
5659

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}"
6065

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}"
6369

6470
ps_user_mark="${normal} ${normal}"
6571
ps_user_input="${normal}"
6672

6773
# 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"
6976
}
7077

7178
# Initialize custom colors
7279
set_custom_colors
7380

74-
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$dark_grey"}
81+
: "${THEME_CLOCK_COLOR:="$dark_grey"}"
7582

7683
# scm theming
7784
SCM_THEME_PROMPT_PREFIX=""
7885
SCM_THEME_PROMPT_SUFFIX=""
7986

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?}"
8592

8693
safe_append_prompt_command prompt_command

0 commit comments

Comments
 (0)