From 9f79848eed84f56d19e1d7bd1133cd44f5164776 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 13:13:06 -0700 Subject: [PATCH 1/4] theme/essential: SC2154 Handle all unbound parameters, even colors! --- themes/essential/essential.theme.bash | 35 ++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/themes/essential/essential.theme.bash b/themes/essential/essential.theme.bash index ae988733..437ae0fc 100644 --- a/themes/essential/essential.theme.bash +++ b/themes/essential/essential.theme.bash @@ -1,42 +1,39 @@ -#!/usr/bin/env bash - -# https://github.com/koalaman/shellcheck/wiki/Sc2154 -# shellcheck disable=SC2154 +# shellcheck shell=bash function _user-prompt() { local -r user='\\u' if [[ "${EUID}" -eq 0 ]]; then # Privileged users: - local -r user_color="${bold_red}" + local -r user_color="${bold_red?}" else # Standard users: - local -r user_color="${bold_green}" + local -r user_color="${bold_green?}" fi # Print the current user's name (colored according to their current EUID): - echo -e "${user_color}${user}${normal}" + echo -e "${user_color}${user}${normal?}" } function _host-prompt() { local -r host='\\h' # Check whether or not $SSH_TTY is set: - if [[ -z "${SSH_TTY}" ]]; then + if [[ -z "${SSH_TTY:-}" ]]; then # For local hosts, set the host's prompt color to blue: - local -r host_color="${bold_blue}" + local -r host_color="${bold_blue?}" else # For remote hosts, set the host's prompt color to red: - local -r host_color="${bold_red}" + local -r host_color="${bold_red?}" fi # Print the current hostname (colored according to $SSH_TTY's status): - echo -e "${host_color}${host}${normal}" + echo -e "${host_color}${host}${normal?}" } function _user-at-host-prompt() { # Concatenate the user and host prompts into: user@host: - echo -e "$(_user-prompt)${bold_white}@$(_host-prompt)" + echo -e "$(_user-prompt)${bold_white?}@$(_host-prompt)" } function _exit-status-prompt() { @@ -47,32 +44,32 @@ function _exit-status-prompt() { if [[ "${exit_status}" -eq 0 ]]; then # For commands that return an exit status of zero, set the exit status's # notifier to green: - local -r exit_status_color="${bold_green}" + local -r exit_status_color="${bold_green?}" else # For commands that return a non-zero exit status, set the exit status's # notifier to red: - local -r exit_status_color="${bold_red}" + local -r exit_status_color="${bold_red?}" fi echo -ne "${exit_status_color}" if [[ "${prompt_string}" -eq 1 ]]; then # $PS1: - echo -e " +${normal} " + echo -e " +${normal?} " elif [[ "${prompt_string}" -eq 2 ]]; then # $PS2: - echo -e " |${normal} " + echo -e " |${normal?} " else # Default: - echo -e " ?${normal} " + echo -e " ?${normal?} " fi } function _ps1() { local -r time='\\t' - echo -ne "${bold_white}${time} " + echo -ne "${bold_white?}${time} " echo -ne "$(_user-at-host-prompt)" - echo -e "${bold_white}:${normal}${PWD}" + echo -e "${bold_white?}:${normal?}${PWD}" echo -e "$(_exit-status-prompt 1 "${exit_status}")" } From d1b71663586f5486c77d704affe3bf28924bb707 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 13:13:57 -0700 Subject: [PATCH 2/4] theme/essential: `shfmt` --- clean_files.txt | 1 + themes/essential/essential.theme.bash | 116 +++++++++++++------------- 2 files changed, 59 insertions(+), 58 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8c8b3fed..5e97dd8c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -135,6 +135,7 @@ themes/brunton themes/candy themes/command_duration.theme.bash themes/easy +themes/essential themes/modern themes/powerline themes/pure diff --git a/themes/essential/essential.theme.bash b/themes/essential/essential.theme.bash index 437ae0fc..02ebe414 100644 --- a/themes/essential/essential.theme.bash +++ b/themes/essential/essential.theme.bash @@ -1,91 +1,91 @@ # shellcheck shell=bash function _user-prompt() { - local -r user='\\u' + local -r user='\\u' - if [[ "${EUID}" -eq 0 ]]; then - # Privileged users: - local -r user_color="${bold_red?}" - else - # Standard users: - local -r user_color="${bold_green?}" - fi + if [[ "${EUID}" -eq 0 ]]; then + # Privileged users: + local -r user_color="${bold_red?}" + else + # Standard users: + local -r user_color="${bold_green?}" + fi - # Print the current user's name (colored according to their current EUID): - echo -e "${user_color}${user}${normal?}" + # Print the current user's name (colored according to their current EUID): + echo -e "${user_color}${user}${normal?}" } function _host-prompt() { - local -r host='\\h' + local -r host='\\h' - # Check whether or not $SSH_TTY is set: - if [[ -z "${SSH_TTY:-}" ]]; then - # For local hosts, set the host's prompt color to blue: - local -r host_color="${bold_blue?}" - else - # For remote hosts, set the host's prompt color to red: - local -r host_color="${bold_red?}" - fi + # Check whether or not $SSH_TTY is set: + if [[ -z "${SSH_TTY:-}" ]]; then + # For local hosts, set the host's prompt color to blue: + local -r host_color="${bold_blue?}" + else + # For remote hosts, set the host's prompt color to red: + local -r host_color="${bold_red?}" + fi - # Print the current hostname (colored according to $SSH_TTY's status): - echo -e "${host_color}${host}${normal?}" + # Print the current hostname (colored according to $SSH_TTY's status): + echo -e "${host_color}${host}${normal?}" } function _user-at-host-prompt() { - # Concatenate the user and host prompts into: user@host: - echo -e "$(_user-prompt)${bold_white?}@$(_host-prompt)" + # Concatenate the user and host prompts into: user@host: + echo -e "$(_user-prompt)${bold_white?}@$(_host-prompt)" } function _exit-status-prompt() { - local -r prompt_string="${1}" - local -r exit_status="${2}" + local -r prompt_string="${1}" + local -r exit_status="${2}" - # Check the exit status of the last command captured by $exit_status: - if [[ "${exit_status}" -eq 0 ]]; then - # For commands that return an exit status of zero, set the exit status's - # notifier to green: - local -r exit_status_color="${bold_green?}" - else - # For commands that return a non-zero exit status, set the exit status's - # notifier to red: - local -r exit_status_color="${bold_red?}" - fi + # Check the exit status of the last command captured by $exit_status: + if [[ "${exit_status}" -eq 0 ]]; then + # For commands that return an exit status of zero, set the exit status's + # notifier to green: + local -r exit_status_color="${bold_green?}" + else + # For commands that return a non-zero exit status, set the exit status's + # notifier to red: + local -r exit_status_color="${bold_red?}" + fi - echo -ne "${exit_status_color}" - if [[ "${prompt_string}" -eq 1 ]]; then - # $PS1: - echo -e " +${normal?} " - elif [[ "${prompt_string}" -eq 2 ]]; then - # $PS2: - echo -e " |${normal?} " - else - # Default: - echo -e " ?${normal?} " - fi + echo -ne "${exit_status_color}" + if [[ "${prompt_string}" -eq 1 ]]; then + # $PS1: + echo -e " +${normal?} " + elif [[ "${prompt_string}" -eq 2 ]]; then + # $PS2: + echo -e " |${normal?} " + else + # Default: + echo -e " ?${normal?} " + fi } function _ps1() { - local -r time='\\t' + local -r time='\\t' - echo -ne "${bold_white?}${time} " - echo -ne "$(_user-at-host-prompt)" - echo -e "${bold_white?}:${normal?}${PWD}" - echo -e "$(_exit-status-prompt 1 "${exit_status}")" + echo -ne "${bold_white?}${time} " + echo -ne "$(_user-at-host-prompt)" + echo -e "${bold_white?}:${normal?}${PWD}" + echo -e "$(_exit-status-prompt 1 "${exit_status}")" } function _ps2() { - echo -e "$(_exit-status-prompt 2 "${exit_status}")" + echo -e "$(_exit-status-prompt 2 "${exit_status}")" } function prompt_command() { - # Capture the exit status of the last command: - local -r exit_status="${?}" + # Capture the exit status of the last command: + local -r exit_status="${?}" - # Build the $PS1 prompt: - PS1="$(_ps1)" + # Build the $PS1 prompt: + PS1="$(_ps1)" - # Build the $PS2 prompt: - PS2="$(_ps2)" + # Build the $PS2 prompt: + PS2="$(_ps2)" } safe_append_prompt_command prompt_command From 3695862b4374bd362ea44510f0308edadae94568 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 31 Dec 2021 23:50:00 -0800 Subject: [PATCH 3/4] theme/essential: cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lose a couple of useless `echo`s/subshells. Alsö, lose the incorrect VIM modeline from the bottom. Our formatting standard is specified in `$BASH_IT/.EditorConfig`. --- themes/essential/essential.theme.bash | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/themes/essential/essential.theme.bash b/themes/essential/essential.theme.bash index 02ebe414..3764b749 100644 --- a/themes/essential/essential.theme.bash +++ b/themes/essential/essential.theme.bash @@ -12,7 +12,7 @@ function _user-prompt() { fi # Print the current user's name (colored according to their current EUID): - echo -e "${user_color}${user}${normal?}" + echo -ne "${user_color}${user}${normal?}" } function _host-prompt() { @@ -28,12 +28,14 @@ function _host-prompt() { fi # Print the current hostname (colored according to $SSH_TTY's status): - echo -e "${host_color}${host}${normal?}" + echo -ne "${host_color}${host}${normal?}" } function _user-at-host-prompt() { # Concatenate the user and host prompts into: user@host: - echo -e "$(_user-prompt)${bold_white?}@$(_host-prompt)" + _user-prompt + echo -ne "${bold_white?}@" + _host-prompt } function _exit-status-prompt() { @@ -54,27 +56,28 @@ function _exit-status-prompt() { echo -ne "${exit_status_color}" if [[ "${prompt_string}" -eq 1 ]]; then # $PS1: - echo -e " +${normal?} " + echo -ne " +${normal?} " elif [[ "${prompt_string}" -eq 2 ]]; then # $PS2: - echo -e " |${normal?} " + echo -ne " |${normal?} " else # Default: - echo -e " ?${normal?} " + echo -ne " ?${normal?} " fi } function _ps1() { local -r time='\\t' + local -r pwd='\\w' echo -ne "${bold_white?}${time} " - echo -ne "$(_user-at-host-prompt)" - echo -e "${bold_white?}:${normal?}${PWD}" - echo -e "$(_exit-status-prompt 1 "${exit_status}")" + _user-at-host-prompt + echo -e "${bold_white?}:${normal?}${pwd}" + _exit-status-prompt 1 "${exit_status}" } function _ps2() { - echo -e "$(_exit-status-prompt 2 "${exit_status}")" + _exit-status-prompt 2 "${exit_status}" } function prompt_command() { @@ -89,5 +92,3 @@ function prompt_command() { } safe_append_prompt_command prompt_command - -# vim: sw=2 ts=2 et: From f2dcb2aff601d0ecc1001f77df168ef7e0634094 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 1 Jan 2022 12:54:32 -0800 Subject: [PATCH 4/4] theme/essential: s/echo/printf/g --- themes/essential/essential.theme.bash | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/themes/essential/essential.theme.bash b/themes/essential/essential.theme.bash index 3764b749..05e84314 100644 --- a/themes/essential/essential.theme.bash +++ b/themes/essential/essential.theme.bash @@ -1,7 +1,7 @@ # shellcheck shell=bash function _user-prompt() { - local -r user='\\u' + local -r user='\u' if [[ "${EUID}" -eq 0 ]]; then # Privileged users: @@ -12,11 +12,11 @@ function _user-prompt() { fi # Print the current user's name (colored according to their current EUID): - echo -ne "${user_color}${user}${normal?}" + printf '%b%s%b' "${user_color}" "${user}" "${normal?}" } function _host-prompt() { - local -r host='\\h' + local -r host='\h' # Check whether or not $SSH_TTY is set: if [[ -z "${SSH_TTY:-}" ]]; then @@ -28,13 +28,13 @@ function _host-prompt() { fi # Print the current hostname (colored according to $SSH_TTY's status): - echo -ne "${host_color}${host}${normal?}" + printf '%b%s%b' "${host_color}" "${host}" "${normal?}" } function _user-at-host-prompt() { # Concatenate the user and host prompts into: user@host: _user-prompt - echo -ne "${bold_white?}@" + printf '%b@' "${bold_white?}" _host-prompt } @@ -53,26 +53,25 @@ function _exit-status-prompt() { local -r exit_status_color="${bold_red?}" fi - echo -ne "${exit_status_color}" if [[ "${prompt_string}" -eq 1 ]]; then # $PS1: - echo -ne " +${normal?} " + printf '%b +%b' "${exit_status_color}" "${normal?} " elif [[ "${prompt_string}" -eq 2 ]]; then # $PS2: - echo -ne " |${normal?} " + printf '%b |%b' "${exit_status_color}" "${normal?} " else # Default: - echo -ne " ?${normal?} " + printf '%b ?%b' "${exit_status_color}" "${normal?} " fi } function _ps1() { - local -r time='\\t' - local -r pwd='\\w' + local -r time='\t' + local -r pwd='\w' - echo -ne "${bold_white?}${time} " + printf '%b%s ' "${bold_white?}" "${time}" _user-at-host-prompt - echo -e "${bold_white?}:${normal?}${pwd}" + printf '%b:%b%s\n' "${bold_white?}" "${normal?}" "${pwd}" _exit-status-prompt 1 "${exit_status}" }