11#! /usr/bin/env bash
22
33# https://github.com/koalaman/shellcheck/wiki/Sc2154
4- # shellcheck disable=SC2154
54
65function _user-prompt() {
76 local -r user=' \\u'
87
98 if [[ " ${EUID} " -eq 0 ]]; then
109 # Privileged users:
11- local -r user_color=" ${bold_red} "
10+ local -r user_color=" ${bold_red? } "
1211 else
1312 # Standard users:
14- local -r user_color=" ${bold_green} "
13+ local -r user_color=" ${bold_green? } "
1514 fi
1615
1716 # Print the current user's name (colored according to their current EUID):
18- echo -e " ${user_color}${user}${normal} "
17+ echo -e " ${user_color}${user}${normal? } "
1918}
2019
2120function _host-prompt() {
2221 local -r host=' \\h'
2322
2423 # Check whether or not $SSH_TTY is set:
25- if [[ -z " ${SSH_TTY} " ]]; then
24+ if [[ -z " ${SSH_TTY:- } " ]]; then
2625 # For local hosts, set the host's prompt color to blue:
27- local -r host_color=" ${bold_blue} "
26+ local -r host_color=" ${bold_blue? } "
2827 else
2928 # For remote hosts, set the host's prompt color to red:
30- local -r host_color=" ${bold_red} "
29+ local -r host_color=" ${bold_red? } "
3130 fi
3231
3332 # Print the current hostname (colored according to $SSH_TTY's status):
34- echo -e " ${host_color}${host}${normal} "
33+ echo -e " ${host_color}${host}${normal? } "
3534}
3635
3736function _user-at-host-prompt() {
3837 # Concatenate the user and host prompts into: user@host:
39- echo -e " $( _user-prompt) ${bold_white} @$( _host-prompt) "
38+ echo -e " $( _user-prompt) ${bold_white? } @$( _host-prompt) "
4039}
4140
4241function _exit-status-prompt() {
@@ -47,32 +46,32 @@ function _exit-status-prompt() {
4746 if [[ " ${exit_status} " -eq 0 ]]; then
4847 # For commands that return an exit status of zero, set the exit status's
4948 # notifier to green:
50- local -r exit_status_color=" ${bold_green} "
49+ local -r exit_status_color=" ${bold_green? } "
5150 else
5251 # For commands that return a non-zero exit status, set the exit status's
5352 # notifier to red:
54- local -r exit_status_color=" ${bold_red} "
53+ local -r exit_status_color=" ${bold_red? } "
5554 fi
5655
5756 echo -ne " ${exit_status_color} "
5857 if [[ " ${prompt_string} " -eq 1 ]]; then
5958 # $PS1:
60- echo -e " +${normal} "
59+ echo -e " +${normal? } "
6160 elif [[ " ${prompt_string} " -eq 2 ]]; then
6261 # $PS2:
63- echo -e " |${normal} "
62+ echo -e " |${normal? } "
6463 else
6564 # Default:
66- echo -e " ?${normal} "
65+ echo -e " ?${normal? } "
6766 fi
6867}
6968
7069function _ps1() {
7170 local -r time=' \\t'
7271
73- echo -ne " ${bold_white}${time} "
72+ echo -ne " ${bold_white? }${time} "
7473 echo -ne " $( _user-at-host-prompt) "
75- echo -e " ${bold_white} :${normal}${PWD} "
74+ echo -e " ${bold_white? } :${normal? }${PWD} "
7675 echo -e " $( _exit-status-prompt 1 " ${exit_status} " ) "
7776}
7877
0 commit comments