From 16b5c0924904df841a4bb90bf6caa71f3fbe322f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 14 Sep 2021 21:53:05 -0700 Subject: [PATCH] themes: disable SC2154, fix SC2155 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each one of these themes will need it’s own fix for SC2154, possibly upstream. Due to the way themes are, it's entirely normal to have a *lot* of false positives for SC2034. So much so, that I have to admit that it is probably just not worth linting for SC2034 despite my dislike of blanket ignore rules. --- themes/90210/90210.theme.bash | 5 ++++- themes/powerline/powerline.base.bash | 22 +++++++++++++--------- themes/powerline/powerline.theme.bash | 1 + themes/purity/purity.theme.bash | 6 ++++-- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/themes/90210/90210.theme.bash b/themes/90210/90210.theme.bash index 180764c8..3db3f17b 100644 --- a/themes/90210/90210.theme.bash +++ b/themes/90210/90210.theme.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX=" |" @@ -11,7 +14,7 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" # Nicely formatted terminal prompt function prompt_command() { - export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " + PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " } safe_append_prompt_command prompt_command diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index 98bcd82c..ade3670d 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + # Define this here so it can be used by all of the Powerline themes THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} @@ -139,7 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd=$(pwd | sed "s|^${HOME}|~|") + local cwd="${PWD/$HOME/\~}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } @@ -157,10 +160,10 @@ function __powerline_clock_prompt() { } function __powerline_battery_prompt() { - local color="" - local battery_status="$(battery_percentage 2> /dev/null)" + local color="" battery_status + battery_status="$(battery_percentage 2> /dev/null)" - if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + if [[ -z "${battery_status}" || "${battery_status}" == "-1" || "${battery_status}" == "no" ]]; then true else if [[ "$((10#${battery_status}))" -le 5 ]]; then @@ -176,7 +179,7 @@ function __powerline_battery_prompt() { } function __powerline_in_vim_prompt() { - if [ -n "$VIMRUNTIME" ]; then + if [[ -n "$VIMRUNTIME" ]]; then echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" fi } @@ -221,7 +224,8 @@ function __powerline_command_number_prompt() { } function __powerline_duration_prompt() { - local duration=$(_command_duration) + local duration + duration=$(_command_duration) [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" } @@ -265,7 +269,7 @@ function __powerline_last_status_prompt() { function __powerline_prompt_command() { local last_status="$?" ## always the first - local separator_char="${POWERLINE_PROMPT_CHAR}" + local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 @@ -277,7 +281,7 @@ function __powerline_prompt_command() { ## left prompt ## for segment in $POWERLINE_PROMPT; do - local info="$(__powerline_"${segment}"_prompt)" + info="$(__powerline_"${segment}"_prompt)" [[ -n "${info}" ]] && __powerline_left_segment "${info}" done @@ -289,7 +293,7 @@ function __powerline_prompt_command() { # By default we try to match the prompt to the adjacent segment's background color, # but when part of the prompt exists within that segment, we instead match the foreground color. - local prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)" + prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)" if [[ -n "${LEFT_PROMPT}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" ]]; then LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" prompt_color="${normal}" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index d7ac77ed..49b397aa 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # shellcheck source=../../themes/powerline/powerline.base.bash . "$BASH_IT/themes/powerline/powerline.base.bash" diff --git a/themes/purity/purity.theme.bash b/themes/purity/purity.theme.bash index 8fc03bf3..22a3fbfb 100644 --- a/themes/purity/purity.theme.bash +++ b/themes/purity/purity.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${bold_red}⊘${normal}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" @@ -26,8 +28,8 @@ venv_prompt() { } function prompt_command() { - retval=$? - local ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" + local retval=$? ret_status + ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)" }