From c6f6d8c27a03cfe67dcf9cefcc32dba73ae549d8 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 9 Sep 2021 11:18:17 +0300 Subject: [PATCH 01/14] plugins: Fix shellcheck warnings on already linted files --- plugins/available/alias-completion.plugin.bash | 2 +- plugins/available/git.plugin.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 390b10e3..0db9b04b 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -70,7 +70,7 @@ function alias_completion { local compl_func="${new_completion/#* -F /}" compl_func="${compl_func%% *}" # avoid recursive call loops by ignoring our own functions - if [[ "${compl_func#_$namespace::}" == "$compl_func" ]]; then + if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then local compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { local compl_word=\$2 diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index e4efc3fe..6a85e7dc 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -309,7 +309,7 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo [$DATE] + echo "[$DATE]" git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" NEXT=$DATE done From ec3b8d645f5d06f840f72a901a5e6c816809cc20 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 10 Sep 2021 16:54:51 +0300 Subject: [PATCH 02/14] Revert "ci: Remove macos-11.0 as it is unreliable" --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcef30aa..03b75882 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0] runs-on: ${{ matrix.os }} From 8c0860588dc2d44a6edba4ee10a9c55e70e1f24f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 23:15:49 -0700 Subject: [PATCH 03/14] themes/base: don't invoke svn if possible If we are specifically in the situation #1612, then check for a working `svn` command. If we're not in that situation, then don't waste time on it. --- test/fixtures/svn/broken/xcrun | 0 test/fixtures/svn/working/xcrun | 0 themes/base.theme.bash | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 test/fixtures/svn/broken/xcrun create mode 100755 test/fixtures/svn/working/xcrun diff --git a/test/fixtures/svn/broken/xcrun b/test/fixtures/svn/broken/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/test/fixtures/svn/working/xcrun b/test/fixtures/svn/working/xcrun new file mode 100755 index 00000000..e69de29b diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 4d6a1b7f..e39dd121 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -92,7 +92,7 @@ SVN_EXE=$(which svn 2> /dev/null || true) # Check for broken SVN exe that is caused by some versions of Xcode. # See https://github.com/Bash-it/bash-it/issues/1612 for more details. -if [[ -x "$SVN_EXE" ]]; then +if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then if ! "$SVN_EXE" --version > /dev/null 2>&1; then # Unset the SVN exe variable so that SVN commands are avoided. SVN_EXE="" From 9c1dbbcf12a59fc5a8c7c4389e283b4e2c02c477 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 29 Jul 2021 00:21:18 -0700 Subject: [PATCH 04/14] lib/scmhelpers: reorder SCM detection waterfall This reduces the need to invoke subprocesses --- themes/base.theme.bash | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e39dd121..51c34e2e 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -104,18 +104,18 @@ function scm { SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM=$SCM_GIT - elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM=$SCM_P4 elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG - elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM=$SCM_HG elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN + elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then + SCM=$SCM_GIT + elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then + SCM=$SCM_HG elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then SCM=$SCM_SVN + elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then + SCM=$SCM_P4 else SCM=$SCM_NONE fi From 476fcb4325837b10bb17a68eb886ac18a909e7c4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 09:59:04 -0700 Subject: [PATCH 05/14] lib/theme: new `_bash_it_appearance_scm_init()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wrap init code in a function and call the function immediately. Several plugins do this, and it allows us to more easily implement a hooks-based system in the future. Alsö, avoid external binary `which`. Use built-in `type -P` instead. Uppercase `-P` forces a path search to avoid hashed matches and functions/aliases and whatnot. --- test/themes/base.theme.svn.bats | 23 ++++++++++++----------- themes/base.theme.bash | 30 +++++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index f2866c8d..d1c2c311 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -7,7 +7,6 @@ load ../../lib/log cite _about _param _example _group _author _version load ../../lib/helpers -load ../../themes/base.theme function local_setup { setup_test_fixture @@ -23,6 +22,8 @@ function local_setup { fi export OLD_PATH="$PATH" + + load ../../themes/base.theme } function local_teardown { @@ -56,8 +57,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -73,8 +74,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -89,8 +90,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used @@ -103,8 +104,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used @@ -120,8 +121,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 51c34e2e..5cc791b4 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -85,19 +85,27 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' -GIT_EXE=$(which git 2> /dev/null || true) -P4_EXE=$(which p4 2> /dev/null || true) -HG_EXE=$(which hg 2> /dev/null || true) -SVN_EXE=$(which svn 2> /dev/null || true) +: "${GIT_EXE:=$SCM_GIT}" +: "${P4_EXE:=$SCM_P4}" +: "${HG_EXE:=$SCM_HG}" +: "${SVN_EXE:=$SCM_SVN}" -# Check for broken SVN exe that is caused by some versions of Xcode. -# See https://github.com/Bash-it/bash-it/issues/1612 for more details. -if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then - if ! "$SVN_EXE" --version > /dev/null 2>&1; then - # Unset the SVN exe variable so that SVN commands are avoided. - SVN_EXE="" +function _bash_it_appearance_scm_init() { + GIT_EXE="$(type -P $SCM_GIT || true)" + P4_EXE="$(type -P $SCM_P4 || true)" + HG_EXE="$(type -P $SCM_HG || true)" + SVN_EXE="$(type -P $SCM_SVN || true)" + + # Check for broken SVN exe that is caused by some versions of Xcode. + # See https://github.com/Bash-it/bash-it/issues/1612 for more details. + if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then + if ! "$SVN_EXE" --version > /dev/null 2>&1; then + # Unset the SVN exe variable so that SVN commands are avoided. + SVN_EXE="" + fi fi -fi +} +_bash_it_appearance_scm_init function scm { if [[ "$SCM_CHECK" = false ]]; then From ffe15ebfe04e19db104527d87d56eefc06841fb6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 13:36:10 -0700 Subject: [PATCH 06/14] themes: use `_save-and-reload-history()` First pass to use _Bash It_'s automatic history management. --- themes/codeword/codeword.theme.bash | 10 +++------- themes/doubletime/doubletime.theme.bash | 6 ++---- .../doubletime_multiline.theme.bash | 6 ++---- .../doubletime_multiline_pyonly.theme.bash | 6 ++---- themes/nwinkler/nwinkler.theme.bash | 6 ++---- .../nwinkler_random_colors.theme.bash | 6 ++---- themes/pete/pete.theme.bash | 6 ++---- themes/rainbowbrite/rainbowbrite.theme.bash | 6 ++---- 8 files changed, 17 insertions(+), 35 deletions(-) mode change 100644 => 100755 themes/doubletime/doubletime.theme.bash mode change 100644 => 100755 themes/doubletime_multiline/doubletime_multiline.theme.bash mode change 100644 => 100755 themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash mode change 100644 => 100755 themes/nwinkler/nwinkler.theme.bash mode change 100644 => 100755 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash mode change 100644 => 100755 themes/pete/pete.theme.bash mode change 100644 => 100755 themes/rainbowbrite/rainbowbrite.theme.bash diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash index e23a3fc3..beab6a4a 100644 --- a/themes/codeword/codeword.theme.bash +++ b/themes/codeword/codeword.theme.bash @@ -1,3 +1,5 @@ +# shellcheck shell=bash + SCM_THEME_PROMPT_PREFIX=${SCM_THEME_PROMPT_SUFFIX} SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}" SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}" @@ -19,11 +21,5 @@ prompt() { PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " } -share_history() { - history -a - history -c - history -r -} - -safe_append_prompt_command share_history +safe_append_prompt_command '_save-and-reload-history 1' safe_append_prompt_command prompt diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash old mode 100644 new mode 100755 index 6b6aa150..8186db73 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash SCM_THEME_PROMPT_DIRTY='' SCM_THEME_PROMPT_CLEAN='' @@ -30,9 +30,7 @@ fi function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w $(scm_prompt)$reset_color $ " diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash old mode 100644 new mode 100755 index 6da88253..18213571 --- a/themes/doubletime_multiline/doubletime_multiline.theme.bash +++ b/themes/doubletime_multiline/doubletime_multiline.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt) \w diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash old mode 100644 new mode 100755 index 5f1951e9..9bc4c334 --- a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash +++ b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt) \w diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash old mode 100644 new mode 100755 index f9fe4933..983c8d00 --- a/themes/nwinkler/nwinkler.theme.bash +++ b/themes/nwinkler/nwinkler.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -29,9 +29,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash old mode 100644 new mode 100755 index f6eff908..05391b0b --- a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash +++ b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -96,9 +96,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/pete/pete.theme.bash b/themes/pete/pete.theme.bash old mode 100644 new mode 100755 index 73fdb053..d29553f8 --- a/themes/pete/pete.theme.bash +++ b/themes/pete/pete.theme.bash @@ -1,10 +1,8 @@ -#!/usr/bin/env bash +# shellcheck shell=bash prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [$blue\u$reset_color@$green\H$reset_color] $yellow\w${reset_color}$(scm_prompt_info)$(ruby_version_prompt) $reset_color " PS2='> ' PS4='+ ' diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash old mode 100644 new mode 100755 index 63c64b72..07e5843f --- a/themes/rainbowbrite/rainbowbrite.theme.bash +++ b/themes/rainbowbrite/rainbowbrite.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # based off of n0qorg # looks like, if you're in a git repo: @@ -7,9 +7,7 @@ prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 # displays user@server in purple # PS1="$red$(scm_char) $purple\u@\h$reset_color:$blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " # no user@server From 9d656747a9761306cf4d9b9875d0c659cc7da88c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 10 Sep 2021 14:01:46 -0700 Subject: [PATCH 07/14] themes: remove executable bit --- themes/demula/demula.theme.bash | 0 themes/doubletime/doubletime.theme.bash | 0 themes/doubletime_multiline/doubletime_multiline.theme.bash | 0 .../doubletime_multiline_pyonly.theme.bash | 0 themes/liquidprompt/liquidprompt.theme.bash | 0 themes/nwinkler/nwinkler.theme.bash | 0 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash | 0 themes/pete/pete.theme.bash | 0 themes/rainbowbrite/rainbowbrite.theme.bash | 0 themes/rana/rana.theme.bash | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 themes/demula/demula.theme.bash mode change 100755 => 100644 themes/doubletime/doubletime.theme.bash mode change 100755 => 100644 themes/doubletime_multiline/doubletime_multiline.theme.bash mode change 100755 => 100644 themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash mode change 100755 => 100644 themes/liquidprompt/liquidprompt.theme.bash mode change 100755 => 100644 themes/nwinkler/nwinkler.theme.bash mode change 100755 => 100644 themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash mode change 100755 => 100644 themes/pete/pete.theme.bash mode change 100755 => 100644 themes/rainbowbrite/rainbowbrite.theme.bash mode change 100755 => 100644 themes/rana/rana.theme.bash diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash old mode 100755 new mode 100644 diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash old mode 100755 new mode 100644 diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash old mode 100755 new mode 100644 diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash old mode 100755 new mode 100644 diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash old mode 100755 new mode 100644 diff --git a/themes/pete/pete.theme.bash b/themes/pete/pete.theme.bash old mode 100755 new mode 100644 diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash old mode 100755 new mode 100644 diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash old mode 100755 new mode 100644 From dee55a03cc373a2ac89a476b61912e7acfe8485a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 23:45:34 -0700 Subject: [PATCH 08/14] drop `dirname` in favor of native Bash strings (1 of 2) Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity. Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user. --- install.sh | 2 +- lib/utilities.bash | 8 ++++---- plugins/available/z_autoenv.plugin.bash | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 4940360f..13721fd2 100755 --- a/install.sh +++ b/install.sh @@ -184,7 +184,7 @@ if [[ $no_modify_config ]] && [[ $append_to_config ]]; then exit 1 fi -BASH_IT="$(cd "$(dirname "$0")" && pwd)" +BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)" case $OSTYPE in darwin*) diff --git a/lib/utilities.bash b/lib/utilities.bash index b6322a1d..e072b52d 100755 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -71,12 +71,12 @@ _bash-it-grep() { ########################################################################### _bash-it-component-help() { - local component=$(_bash-it-pluralize-component "${1}") - local file=$(_bash-it-component-cache-file ${component}) + local component="$(_bash-it-pluralize-component "${1}")" + local file="$(_bash-it-component-cache-file "${component}")" if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then rm -f "${file}" 2>/dev/null local func="_bash-it-${component}" - ${func} | $(_bash-it-grep) -E ' \[' | cat > ${file} + "${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}" fi cat "${file}" } @@ -84,7 +84,7 @@ _bash-it-component-help() { _bash-it-component-cache-file() { local component=$(_bash-it-pluralize-component "${1}") local file="${BASH_IT}/tmp/cache/${component}" - [[ -f ${file} ]] || mkdir -p $(dirname ${file}) + [[ -f "${file}" ]] || mkdir -p "${file%/*}" printf "${file}" } diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 553a7ba3..a2f97d28 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -11,7 +11,7 @@ autoenv_init() typeset target home _file typeset -a _files target=$1 - home="$(dirname "$HOME")" + home="${HOME%/*}" _files=( $( while [[ "$PWD" != "/" && "$PWD" != "$home" ]] From 470341b23aef737faedc0c77909bfc21cc28abc0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 23:47:10 -0700 Subject: [PATCH 09/14] Drop `basename` in favor of Bash strings Convert `var=$(basename $file)` to `var="${file##*/}"` --- lib/helpers.bash | 10 +++++----- plugins/available/jekyll.plugin.bash | 10 +++++----- plugins/available/osx-timemachine.plugin.bash | 2 +- plugins/available/virtualenv.plugin.bash | 12 +++++++----- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index a528c14c..9b95fe65 100755 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -340,7 +340,7 @@ _bash-it-migrate() { do for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` do - typeset ff=$(basename $f) + typeset ff="${f##*/}" # Get the type of component from the extension typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') @@ -501,7 +501,7 @@ _bash-it-describe () do # Check for both the old format without the load priority, and the extended format with the priority declare enabled_files enabled_file - enabled_file=$(basename $f) + enabled_file="${f##*/}" enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l) if [ $enabled_files -gt 0 ]; then @@ -603,9 +603,9 @@ _disable-thing () printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return fi - rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" + rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}" else - rm "${BASH_IT}/enabled/$(basename $plugin_global)" + rm "${BASH_IT}/enabled/${plugin_global##*/}" fi fi @@ -681,7 +681,7 @@ _enable-thing () return fi - to_enable=$(basename $to_enable) + to_enable="${to_enable##*/}" # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) if [ ! -z "$enabled_plugin" ] ; then diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash index 6254a87f..c340c432 100644 --- a/plugins/available/jekyll.plugin.bash +++ b/plugins/available/jekyll.plugin.bash @@ -16,7 +16,7 @@ editpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -77,7 +77,7 @@ newpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site JEKYLL_FORMATTING=${MARKUPS[$loc]} @@ -280,7 +280,7 @@ function testsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -312,7 +312,7 @@ function buildsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -347,7 +347,7 @@ function deploysite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site REMOTE=${REMOTES[$loc]} diff --git a/plugins/available/osx-timemachine.plugin.bash b/plugins/available/osx-timemachine.plugin.bash index f29d6ece..3d7ff00c 100644 --- a/plugins/available/osx-timemachine.plugin.bash +++ b/plugins/available/osx-timemachine.plugin.bash @@ -15,7 +15,7 @@ function time-machine-list-machines() { local tmdest="$(time-machine-destination)/Backups.backupdb" find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do - echo "$(basename "$line")" + echo "${line##*/}" done } diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index 468870cd..f1c85987 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -14,8 +14,8 @@ function mkvenv { about 'create a new virtualenv for this directory' group 'virtualenv' - cwd=`basename \`pwd\`` - mkvirtualenv --distribute $cwd + local cwd="${PWD##*/}" + mkvirtualenv --distribute "$cwd" } @@ -23,19 +23,21 @@ function mkvbranch { about 'create a new virtualenv for the current branch' group 'virtualenv' - mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" } function wovbranch { about 'sets workon branch' group 'virtualenv' - workon "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + workon "${cwd}@${SCM_BRANCH}" } function wovenv { about 'works on the virtualenv for this directory' group 'virtualenv' - workon "$(basename `pwd`)" + workon "${PWD##*/}" } From 435151819f0d76819256d03285fea4004432bee2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 14 Sep 2021 23:30:05 -0700 Subject: [PATCH 10/14] EditorConfig: set `indent_size = tab` Despite `indent_size` being set to `tab` by default, it turns out that we set `indent_size` to `2` for `*` at the top of this file. So, for everywhere else, explicitly set `indent_size` to the default (`tab`). This should achieve the goal of my last patch to `.editorconfig`. --- .editorconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index e0eb8455..8a181ef5 100755 --- a/.editorconfig +++ b/.editorconfig @@ -13,16 +13,18 @@ insert_final_newline = true trim_trailing_whitespace = false [.git*] +indent_size = tab indent_style = tab [{**.*sh,test/run}] +indent_size = tab indent_style = tab shell_variant = bash binary_next_line = true # like -bn switch_case_indent = true # like -ci space_redirects = true # like -sr -keep_padding = false # like -kp +keep_padding = false # like -kp end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From 1c3cbf7ca66dc0dc357683c936fdc8d3963212b3 Mon Sep 17 00:00:00 2001 From: John D Pell <52194+gaelicWizard@users.noreply.github.com> Date: Sat, 18 Sep 2021 02:50:59 -0700 Subject: [PATCH 11/14] Delete `.shellcheckrc` (#1947) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CI: disable Ubuntu 16.04 as it's EOL https://github.blog/changelog/2021-04-29-github-actions-ubuntu-16-04-lts-virtual-environment-will-be-removed-on-september-20-2021/ * main: lint false positive * install: lint * plugins/cmd-returned-notify: don't `export` * plugins/xterm: lint * plugins/git: lint * plugins/goenv: lint * plugins/alias-completion: lint false positives * plugins/alias-completion: fix SC2155, SC2154 Declare `locals` at the top of the function * completion: lint completions using `bash_completion` functions Match the style of the existing code * completion/knife: lint false positives * completion/knife: lint * completion/sdkman: lint * completion/composer: lint * Move `.shellcheckrc` under `themes/` * lib/theme: fix SC2155, SC2154, SC2034 * lib/colors: don't warn on unused variables We assign a large number of variables here and they may or may not be used anywhere else, so disable SC2034 for this file (only). Alsö disable SC2005 as the functions in this file were written before `printf` was invented and have to do some fancy metascripting to get escape sequences interpreted reliably. I’m not smart enough to fix this to use `printf`, so leave it for now. * themes/agnoster: lint * themes: disable SC2154 for colors 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: disable SC2154, fix SC2155 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. * Delete `.shellcheckrc` * remove executable bit --- .github/workflows/ci.yml | 2 +- .shellcheckrc | 6 -- bash_it.sh | 3 +- completion/available/composer.completion.bash | 14 ++-- completion/available/dart.completion.bash | 2 + .../available/dmidecode.completion.bash | 2 + completion/available/knife.completion.bash | 12 ++-- completion/available/ngrok.completion.bash | 2 + .../available/notify-send.completion.bash | 2 + completion/available/sdkman.completion.bash | 16 +++-- completion/available/vuejs.completion.bash | 2 + hooks/dot-bash.sh | 2 +- hooks/dot-sh.sh | 2 +- install.sh | 28 ++++---- lib/helpers.bash | 0 lib/log.bash | 0 lib/search.bash | 0 lib/utilities.bash | 0 .../available/alias-completion.plugin.bash | 23 +++--- .../available/cmd-returned-notify.plugin.bash | 2 +- plugins/available/git.plugin.bash | 71 +++++++++---------- plugins/available/goenv.plugin.bash | 2 +- plugins/available/xterm.plugin.bash | 24 ++++--- scripts/reloader.bash | 3 +- themes/90210/90210.theme.bash | 5 +- themes/agnoster/agnoster.theme.bash | 3 +- themes/atomic/atomic.theme.bash | 2 + themes/bakke/bakke.theme.bash | 2 + themes/barbuk/barbuk.theme.bash | 2 + themes/base.theme.bash | 22 +++--- themes/binaryanomaly/binaryanomaly.theme.bash | 2 + themes/bira/bira.theme.bash | 2 + themes/bobby-python/bobby-python.theme.bash | 2 + themes/bobby/bobby.theme.bash | 2 + themes/brainy/brainy.theme.bash | 2 + themes/brunton/brunton.theme.bash | 2 + themes/candy/candy.theme.bash | 2 + themes/colors.theme.bash | 4 +- themes/easy/easy.theme.bash | 2 + themes/modern/modern.theme.bash | 2 + themes/powerline/powerline.base.bash | 22 +++--- themes/powerline/powerline.theme.bash | 1 + themes/pure/pure.theme.bash | 2 + themes/purity/purity.theme.bash | 6 +- 44 files changed, 183 insertions(+), 126 deletions(-) delete mode 100644 .shellcheckrc mode change 100755 => 100644 lib/helpers.bash mode change 100755 => 100644 lib/log.bash mode change 100755 => 100644 lib/search.bash mode change 100755 => 100644 lib/utilities.bash mode change 100644 => 100755 scripts/reloader.bash diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03b75882..f42c096b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0] + os: [ubuntu-20.04, ubuntu-18.04, macos-10.15, macos-11.0] runs-on: ${{ matrix.os }} diff --git a/.shellcheckrc b/.shellcheckrc deleted file mode 100644 index 6418bd8f..00000000 --- a/.shellcheckrc +++ /dev/null @@ -1,6 +0,0 @@ -# We use colors and not assigned -disable=SC2154 -# Hard to fix -disable=SC2155 -# shellcheck is wrong on some -disable=SC2034 diff --git a/bash_it.sh b/bash_it.sh index b8d3aeef..679ffdaf 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -114,6 +114,7 @@ for _bash_it_config_file in $CUSTOM; do if [ -e "${_bash_it_config_file}" ]; then filename=$(basename "${_bash_it_config_file}") filename=${filename%*.bash} + # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..." # shellcheck disable=SC1090 @@ -122,7 +123,7 @@ for _bash_it_config_file in $CUSTOM; do done unset _bash_it_config_file -if [[ "${PROMPT:-}" ]]; then +if [[ -n "${PROMPT:-}" ]]; then export PS1="\[""$PROMPT""\]" fi diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index eefe50fa..176f0832 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -3,14 +3,14 @@ cite "about-completion" about-completion "composer completion" function __composer_completion() { - local cur coms opts com + local cur coms opts com words COMPREPLY=() _get_comp_words_by_ref -n : cur words # lookup for command for word in "${words[@]:1}"; do - if [[ $word != -* ]]; then - com=$word + if [[ "${word}" != -* ]]; then + com="${word}" break fi done @@ -19,7 +19,7 @@ function __composer_completion() { if [[ ${cur} == --* ]]; then opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" - case "$com" in + case "${com}" in about) opts="${opts} " ;; @@ -109,18 +109,18 @@ function __composer_completion() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi # completing for a command - if [[ "$cur" == "$com" ]]; then + if [[ "${cur}" == "${com}" ]]; then coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate" # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash index ece96d5c..b7563443 100644 --- a/completion/available/dart.completion.bash +++ b/completion/available/dart.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __dart_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) local HELP="--help -h" diff --git a/completion/available/dmidecode.completion.bash b/completion/available/dmidecode.completion.bash index fc50c1f0..4a884524 100644 --- a/completion/available/dmidecode.completion.bash +++ b/completion/available/dmidecode.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __dmidecode_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index 83b332f9..4b9950ed 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -42,6 +42,7 @@ _KAC_is_file_newer_than() { _KAC_regen_cache() { local CACHE_NAME=$1 local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME" + # shellcheck disable=SC2155 local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX") shift 1 # discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated @@ -66,6 +67,7 @@ _KAC_get_command_from_cache_name() { # otherwise it waits for the cache to be generated # in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable # for obvious reason, do NOT call that in a sub-shell (in particular, no piping) +# shellcheck disable=SC2155 _KAC_get_and_regen_cache() { # the cache name can't have space in it local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@") @@ -100,7 +102,7 @@ _KAC_clean_cache() { # perform a cache cleaning when loading this file # On big systems this could baloon up to a 30 second run or more, so not enabling by default. -[[ "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache +[[ -n "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache ##################################### ### End of cache helper functions ### @@ -118,7 +120,7 @@ _KAC_get_current_base_command() { local PREVIOUS="knife" local I=1 local CURRENT - while [ $I -le "$COMP_CWORD" ]; do + while [[ "${I}" -le "${COMP_CWORD}" ]]; do # command words are all lower-case echo "${COMP_WORDS[$I]}" | grep -E "^[a-z]+$" > /dev/null || break CURRENT="$PREVIOUS ${COMP_WORDS[$I]}" @@ -127,12 +129,13 @@ _KAC_get_current_base_command() { I=$((I + 1)) done _KAC_CURRENT_COMMAND=$PREVIOUS - [ $I -le "$COMP_CWORD" ] && _KAC_CURRENT_COMMAND_NB_WORDS=$I + [[ "${I}" -le "${COMP_CWORD}" ]] && _KAC_CURRENT_COMMAND_NB_WORDS="${I}" } # searches the position of the currently completed argument in the current base command # (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...) # assumes the current base command is complete +# shellcheck disable=SC2155 _KAC_get_current_arg_position() { local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1)) local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH") @@ -150,10 +153,11 @@ _KAC_get_current_arg_position() { _knife() { _KAC_get_and_regen_cache _KAC_knife_commands local RAW_LIST ITEM REGEN_CMD ARG_POSITION + # shellcheck disable=SC2034 COMREPLY=() # get correct command & arg pos _KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$((COMP_CWORD + 1)) - RAW_LIST=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH" | cut -d ' ' -f $ARG_POSITION | uniq) + RAW_LIST=$(grep -E "^${_KAC_CURRENT_COMMAND}" "${_KAC_CACHE_PATH}" | cut -d ' ' -f "${ARG_POSITION}" | uniq) # we need to process that raw list a bit, most notably for placeholders # NOTE: I chose to explicitely fetch & cache _certain_ informations for the server (cookbooks & node names, etc) diff --git a/completion/available/ngrok.completion.bash b/completion/available/ngrok.completion.bash index ffbdd3c8..ca50a16f 100644 --- a/completion/available/ngrok.completion.bash +++ b/completion/available/ngrok.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __ngrok_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) local BASE_NO_CONF="--log --log-format --log-level --help" diff --git a/completion/available/notify-send.completion.bash b/completion/available/notify-send.completion.bash index b2c171e9..676485f8 100644 --- a/completion/available/notify-send.completion.bash +++ b/completion/available/notify-send.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __notify-send_completions() { + # shellcheck disable=SC2155 local curr=$(_get_cword) + # shellcheck disable=SC2155 local prev=$(_get_pword) case $prev in diff --git a/completion/available/sdkman.completion.bash b/completion/available/sdkman.completion.bash index 7f0157f3..2dc09088 100644 --- a/completion/available/sdkman.completion.bash +++ b/completion/available/sdkman.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash -_sdkman_complete() { + +function _sdkman_complete() { local CANDIDATES local CANDIDATE_VERSIONS + local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}" COMPREPLY=() @@ -10,7 +12,7 @@ _sdkman_complete() { elif [ "$COMP_CWORD" -eq 2 ]; then case "${COMP_WORDS[COMP_CWORD - 1]}" in "install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug") - CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') + CANDIDATES="${SDKMAN_CANDIDATES_CSV//,/${IFS:0:1}}" mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}") ;; "env") @@ -46,17 +48,17 @@ _sdkman_complete() { return 0 } -_sdkman_candidate_local_versions() { +function _sdkman_candidate_local_versions() { CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1") } -_sdkman_candidate_all_versions() { +function _sdkman_candidate_all_versions() { candidate="$1" CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate") - if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then + if [[ "${SDKMAN_OFFLINE_MODE:-false}" == "true" ]]; then CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS else # sdkman has a specific output format for Java candidate since @@ -70,12 +72,12 @@ _sdkman_candidate_all_versions() { # "+" - local version # "*" - installed # ">" - currently in use - CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort | uniq -u) " + CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort -u) " fi } -__sdkman_cleanup_local_versions() { +function __sdkman_cleanup_local_versions() { __sdkman_build_version_csv "$1" | tr ',' ' ' diff --git a/completion/available/vuejs.completion.bash b/completion/available/vuejs.completion.bash index bbd79b9c..751658f0 100644 --- a/completion/available/vuejs.completion.bash +++ b/completion/available/vuejs.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __vuejs_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 7a9dc8bc..253cb595 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/hooks/dot-sh.sh b/hooks/dot-sh.sh index 3fa63216..e1086bb6 100755 --- a/hooks/dot-sh.sh +++ b/hooks/dot-sh.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/install.sh b/install.sh index 4940360f..45c975fd 100755 --- a/install.sh +++ b/install.sh @@ -83,8 +83,8 @@ function _bash-it_check_for_backup() { fi echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 - if ! [[ $overwrite_backup ]]; then - while ! [[ $silent ]]; do + if [[ -z "${overwrite_backup}" ]]; then + while [[ -z "${silent}" ]]; do read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP case $RESP in [yY]) @@ -100,9 +100,9 @@ function _bash-it_check_for_backup() { esac done fi - if ! [[ $overwrite_backup ]]; then + if [[ -z "${overwrite_backup}" ]]; then echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" - if [[ $silent ]]; then + if [[ -n "${silent}" ]]; then echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m" fi exit 1 @@ -114,8 +114,8 @@ function _bash-it_check_for_backup() { function _bash-it_modify_config_files() { _bash-it_check_for_backup - if ! [[ $silent ]]; then - while ! [[ $append_to_config ]]; do + if [[ -z "${silent}" ]]; then + while [[ -z "${append_to_config}" ]]; do read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice case $choice in [yY]) @@ -131,7 +131,7 @@ function _bash-it_modify_config_files() { esac done fi - if [[ $append_to_config ]]; then + if [[ -n "${append_to_config}" ]]; then # backup/append _bash-it_backup_append else @@ -174,12 +174,12 @@ done shift $((OPTIND - 1)) -if [[ $silent ]] && [[ $interactive ]]; then +if [[ -n "${silent}" && -n "${interactive}" ]]; then echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi -if [[ $no_modify_config ]] && [[ $append_to_config ]]; then +if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi @@ -197,7 +197,7 @@ esac BACKUP_FILE=$CONFIG_FILE.bak echo "Installing bash-it" -if ! [[ $no_modify_config ]]; then +if [[ -z "${no_modify_config}" ]]; then _bash-it_modify_config_files fi @@ -212,10 +212,10 @@ cite _about _param _example _group _author _version # shellcheck source=./lib/helpers.bash source "$BASH_IT/lib/helpers.bash" -if [[ $interactive ]] && ! [[ $silent ]]; then +if [[ -n $interactive && -z "${silent}" ]]; then for type in "aliases" "plugins" "completion"; do - echo -e "\033[0;32mEnabling $type\033[0m" - _bash-it_load_some $type + echo -e "\033[0;32mEnabling ${type}\033[0m" + _bash-it_load_some "$type" done else echo "" @@ -230,7 +230,7 @@ fi echo "" echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" # shellcheck disable=SC2086 -echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m" +echo -e "\033[0;32mTo start using it, open a new tab or 'source "~/$CONFIG_FILE"'.\033[0m" echo "" echo "To show the available aliases/completions/plugins, type one of the following:" echo " bash-it show aliases" diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100755 new mode 100644 diff --git a/lib/log.bash b/lib/log.bash old mode 100755 new mode 100644 diff --git a/lib/search.bash b/lib/search.bash old mode 100755 new mode 100644 diff --git a/lib/utilities.bash b/lib/utilities.bash old mode 100755 new mode 100644 diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 0db9b04b..eb368d93 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -19,6 +19,8 @@ about-plugin 'Automatic completion of aliases' # Automatically add completion for all aliases to commands having completion functions function alias_completion { local namespace="alias_completion" + local tmp_file completion_loader alias_name alias_tokens line completions + local alias_arg_words new_completion compl_func compl_wrapper # parse function based completion definitions, where capture group 2 => function and 3 => trigger local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' @@ -26,28 +28,25 @@ function alias_completion { local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" # create array of function completion triggers, keeping multi-word triggers together - eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" + eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" ((${#completions[@]} == 0)) && return 0 # create temporary file for wrapper functions and completions - local tmp_file tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 - local completion_loader completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')" # read in " '' ''" lines from defined aliases - local line - - # shellcheck disable=SC2162 # some aliases do have backslashes that needs to be interpreted + # shellcheck disable=SC2162 while read line; do - eval "local alias_tokens; alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error - local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" + eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error + # shellcheck disable=SC2154 # see `eval` above + alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" # skip aliases to pipes, boolean control structures and other command lists # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters) - eval "local alias_arg_words; alias_arg_words=($alias_args)" 2> /dev/null || continue + eval "alias_arg_words=($alias_args)" 2> /dev/null || continue # avoid expanding wildcards read -a alias_arg_words <<< "$alias_args" @@ -63,15 +62,15 @@ function alias_completion { continue fi fi - local new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" + new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" # create a wrapper inserting the alias arguments if any if [[ -n $alias_args ]]; then - local compl_func="${new_completion/#* -F /}" + compl_func="${new_completion/#* -F /}" compl_func="${compl_func%% *}" # avoid recursive call loops by ignoring our own functions if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then - local compl_wrapper="_${namespace}::${alias_name}" + compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { local compl_word=\$2 local prec_word=\$3 diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index a3050875..d9be5e4e 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -9,7 +9,7 @@ precmd_return_notification() { } preexec_return_notification() { - [ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s) + [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) } precmd_functions+=(precmd_return_notification) diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index 6a85e7dc..3a130955 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -2,12 +2,13 @@ cite about-plugin about-plugin 'git helper functions' +# shellcheck disable=SC2016 function git_remote { - about "adds remote $GIT_HOSTING:$1 to current repo" + about 'adds remote $GIT_HOSTING:$1 to current repo' group "git" - echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" - git remote add origin "$GIT_HOSTING:$1".git + echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git" + git remote add origin "${GIT_HOSTING}:${1}".git } function git_first_push { @@ -24,14 +25,14 @@ function git_pub() { BRANCH=$(git rev-parse --abbrev-ref HEAD) echo "Publishing ${BRANCH} to remote origin" - git push -u origin "$BRANCH" + git push -u origin "${BRANCH}" } function git_revert() { about 'applies changes to HEAD that revert all changes after this commit' group 'git' - git reset "$1" + git reset "${1:?}" git reset --soft "HEAD@{1}" git commit -m "Revert to ${1}" git reset --hard @@ -49,9 +50,7 @@ function git_rollback() { } function commit_exists() { - git rev-list --quiet "$1" - status=$? - if [ $status -ne 0 ]; then + if git rev-list --quiet "${1:?}"; then echo "Commit ${1} does not exist" kill -INT $$ fi @@ -61,7 +60,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) echo "Rolling back to commit ${1} with unstaged changes" @@ -87,7 +86,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) keep_changes "$1" @@ -134,8 +133,8 @@ function git_info() { # print all remotes and thier details for remote in $(git remote show); do - echo "$remote": - git remote show "$remote" + echo "${remote}": + git remote show "${remote}" echo done @@ -172,32 +171,32 @@ function git_stats { AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ') LOGOPTS="" if [ "$1" == '-w' ]; then - LOGOPTS="$LOGOPTS -w" + LOGOPTS="${LOGOPTS} -w" shift fi if [ "$1" == '-M' ]; then - LOGOPTS="$LOGOPTS -M" + LOGOPTS="${LOGOPTS} -M" shift fi if [ "$1" == '-C' ]; then - LOGOPTS="$LOGOPTS -C --find-copies-harder" + LOGOPTS="${LOGOPTS} -C --find-copies-harder" shift fi - for a in $AUTHORS; do + for a in ${AUTHORS}; do echo '-------------------' - echo "Statistics for: $a" + echo "Statistics for: ${a}" echo -n "Number of files changed: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l echo -n "Number of lines added: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}' echo -n "Number of lines deleted: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}' echo -n "Number of merges: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit' + git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit' done else echo "you're currently not in a git repository" @@ -212,18 +211,16 @@ function gittowork() { result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null) - if [[ $result =~ ERROR ]]; then + if [[ "${result}" =~ ERROR ]]; then echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'" - elif [[ $1 = list ]]; then - echo "$result" + elif [[ $1 == list ]]; then + echo "${result}" else if [[ -f .gitignore ]]; then - result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io") + result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}") echo ".gitignore already exists, appending..." - echo "$result" >> .gitignore - else - echo "$result" > .gitignore fi + echo "${result}" >> .gitignore fi } @@ -257,7 +254,7 @@ function gitignore-reload() { fi # Prompt user to commit or stash changes and exit - if [ $err = 1 ]; then + if [[ "${err}" == 1 ]]; then echo >&2 "Please commit or stash them." fi @@ -265,7 +262,7 @@ function gitignore-reload() { # If we're here, then there are no uncommited or unstaged changes dangling around. # Proceed to reload .gitignore - if [ $err = 0 ]; then + if [[ "${err}" == 0 ]]; then # Remove all cached files git rm -r --cached . @@ -290,6 +287,7 @@ function git-changelog() { return 1 fi + # shellcheck disable=SC2155 local NEXT=$(date +%F) if [[ "$2" == "md" ]]; then @@ -298,9 +296,9 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo "### $DATE" - git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "### ${DATE}" + git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + NEXT=${DATE} done else echo "CHANGELOG $1" @@ -309,9 +307,10 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo "[$DATE]" - git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "[${DATE}]" + git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + # shellcheck disable=SC2034 + NEXT=${DATE} done fi } diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index d00fce67..17e4a0ff 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -30,7 +30,7 @@ eval "$(goenv init - bash)" # If moving to a directory with a goenv version set, reload the shell # to ensure the shell environment matches expectations. _bash-it-goenv-preexec() { - export GOENV_OLD_VERSION="$(goenv version-name)" + GOENV_OLD_VERSION="$(goenv version-name)" } _bash-it-goenv-precmd() { if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index 4f4fd50d..b8747a25 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -3,29 +3,37 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' _short-dirname() { - local dir_name=$(dirs +0) - [ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" + local dir_name="${PWD/~/\~}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then + echo "${dir_name##*/}" + else + echo "${dir_name}" + fi } _short-command() { local input_command="$*" - [ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then + echo "${input_command%% *}" + else + echo "${input_command}" + fi } set_xterm_title() { - local title="$1" - echo -ne "\033]0;$title\007" + local title="${1:-}" + echo -ne "\033]0;${title}\007" } precmd_xterm_title() { - set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR" + set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}" } preexec_xterm_title() { - set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" + set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } -case "$TERM" in +case "${TERM:-dumb}" in xterm* | rxvt*) precmd_functions+=(precmd_xterm_title) preexec_functions+=(preexec_xterm_title) diff --git a/scripts/reloader.bash b/scripts/reloader.bash old mode 100644 new mode 100755 index f22de67e..4bc24941 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -5,6 +5,7 @@ function _set-prefix-based-on-path() { filename=$(_bash-it-get-component-name-from-path "$1") extension=$(_bash-it-get-component-type-from-path "$1") + # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="$extension: $filename: " } @@ -15,7 +16,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then alias|completion|plugin) _bash_it_config_type=$1 _log_debug "Loading enabled $1 components..." ;; - *|'') + ''|*) _log_debug "Loading all enabled components..." ;; esac 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/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index ba3e2c9a..20c184f3 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # vim: ft=bash ts=2 sw=2 sts=2 # # agnoster's Theme - https://gist.github.com/3712874 @@ -220,7 +221,7 @@ prompt_virtualenv() { # Context: user@hostname (who am I and where am I) prompt_context() { - local user=$(whoami) + local user="${USER:-${LOGNAME:?}}" if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then prompt_segment black default "$user@\h" diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 6bde6801..03dc9e95 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Atomic Bash Prompt for Bash-it # By lfelipe base on the theme brainy of MunifTanjim diff --git a/themes/bakke/bakke.theme.bash b/themes/bakke/bakke.theme.bash index 725350a0..d7bfbbe8 100644 --- a/themes/bakke/bakke.theme.bash +++ b/themes/bakke/bakke.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=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 8e09d4be..b614d148 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Theme custom glyphs SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '} diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 5cc791b4..1e0409d3 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX='' @@ -130,12 +131,11 @@ function scm { } scm_prompt() { - local CHAR=$(scm_char) + local CHAR + CHAR="$(scm_char)" local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} - if [[ $CHAR = "$SCM_NONE_CHAR" ]]; then - return - else + if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then # shellcheck disable=2059 printf "$format\n" "$CHAR" "$(scm_prompt_info)" fi @@ -352,15 +352,15 @@ function svn_prompt_vars { # - .hg is located in ~/Projects/Foo/.hg # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo function get_hg_root { - local CURRENT_DIR=$(pwd) + local CURRENT_DIR="${PWD}" - while [ "$CURRENT_DIR" != "/" ]; do - if [ -d "$CURRENT_DIR/.hg" ]; then + while [[ "${CURRENT_DIR:-/}" != "/" ]]; do + if [[ -d "$CURRENT_DIR/.hg" ]]; then echo "$CURRENT_DIR/.hg" return fi - CURRENT_DIR=$(dirname "$CURRENT_DIR") + CURRENT_DIR="${CURRENT_DIR%/*}" done } @@ -552,7 +552,7 @@ function prompt_char { function battery_char { if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then - echo -e "${bold_red}$(battery_percentage)%" + echo -e "${bold_red:-}$(battery_percentage)%" fi } @@ -594,7 +594,7 @@ function __check_precmd_conflict() { function safe_append_prompt_command { local prompt_re - if [ "${__bp_imported}" == "defined" ]; then + if [ "${__bp_imported:-missing}" == "defined" ]; then # We are using bash-preexec if ! __check_precmd_conflict "${1}"; then precmd_functions+=("${1}") @@ -609,7 +609,7 @@ function safe_append_prompt_command { prompt_re="\<${1}\>" fi - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then + if [[ ${PROMPT_COMMAND[*]:-} =~ ${prompt_re} ]]; then return elif [[ -z ${PROMPT_COMMAND} ]]; then PROMPT_COMMAND="${1}" diff --git a/themes/binaryanomaly/binaryanomaly.theme.bash b/themes/binaryanomaly/binaryanomaly.theme.bash index c2efa237..c4488c4c 100644 --- a/themes/binaryanomaly/binaryanomaly.theme.bash +++ b/themes/binaryanomaly/binaryanomaly.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Detect whether a reboot is required function show_reboot_required() { diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index ae8f0efe..7db03000 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.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_PREFIX=" ${yellow}‹" SCM_THEME_PROMPT_SUFFIX="›${reset_color}" diff --git a/themes/bobby-python/bobby-python.theme.bash b/themes/bobby-python/bobby-python.theme.bash index 9144e251..ebb3eab0 100644 --- a/themes/bobby-python/bobby-python.theme.bash +++ b/themes/bobby-python/bobby-python.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=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index bdf388f7..98d2cd8d 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.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=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index db8377ba..e1c36175 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Brainy Bash Prompt for Bash-it # by MunifTanjim diff --git a/themes/brunton/brunton.theme.bash b/themes/brunton/brunton.theme.bash index 27b822ca..166fcc84 100644 --- a/themes/brunton/brunton.theme.bash +++ b/themes/brunton/brunton.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_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" diff --git a/themes/candy/candy.theme.bash b/themes/candy/candy.theme.bash index be53d373..7753e934 100644 --- a/themes/candy/candy.theme.bash +++ b/themes/candy/candy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. function prompt_command() { PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} ${normal}" diff --git a/themes/colors.theme.bash b/themes/colors.theme.bash index fbb1dc5c..d5044d05 100644 --- a/themes/colors.theme.bash +++ b/themes/colors.theme.bash @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2005 +# shellcheck disable=SC2034 function __ { echo "$@" diff --git a/themes/easy/easy.theme.bash b/themes/easy/easy.theme.bash index a48eb824..7e2e3389 100644 --- a/themes/easy/easy.theme.bash +++ b/themes/easy/easy.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_PREFIX="${bold_green}[ ${normal}" SCM_THEME_PROMPT_SUFFIX="${bold_green} ] " diff --git a/themes/modern/modern.theme.bash b/themes/modern/modern.theme.bash index 3a51267c..eadb0762 100644 --- a/themes/modern/modern.theme.bash +++ b/themes/modern/modern.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_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" 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/pure/pure.theme.bash b/themes/pure/pure.theme.bash index 3672a72c..99476f4a 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # scm theming SCM_THEME_PROMPT_PREFIX="|" 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)" } From 1f6d6aa147d47b69e23e390bca662494bebba0d9 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 5 Sep 2021 17:28:54 -0700 Subject: [PATCH 12/14] Use `$PWD` instead of `\`pwd\`` Don't subshell when there's a shell parameter for it. --- completion/available/gradle.completion.bash | 4 ++-- plugins/available/dirs.plugin.bash | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 2b33383f..6ec8c697 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -23,8 +23,8 @@ COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') __gradle-set-project-root-dir() { - local dir=`pwd` - project_root_dir=`pwd` + local dir="${PWD}" + project_root_dir="${PWD}" while [[ $dir != '/' ]]; do if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then project_root_dir=$dir diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index c215f7ec..5f27db01 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -86,7 +86,7 @@ S () { sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; - echo "$@"=\"`pwd`\" >> ~/.dirs; + echo "$@"=\""${PWD}"\" >> ~/.dirs; source ~/.dirs ; } From 5fc418e479aa79a6192182b93ef4b6d5801cb7c6 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 18 Sep 2021 13:15:13 -0700 Subject: [PATCH 13/14] Use `${PWD}` instead of `$(pwd)` Don't subshell when there's a shell parameter for it. --- completion/available/hub.completion.bash | 2 +- lib/helpers.bash | 2 +- plugins/available/dirs.plugin.bash | 4 ++-- themes/powerturk/powerturk.theme.bash | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 themes/powerturk/powerturk.theme.bash diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 79d76bf0..74c530a8 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -227,7 +227,7 @@ EOF ((c++)) done if [ -z "$name" ]; then - repo=$(basename "$(pwd)") + repo="$(basename "${PWD}")" fi case "$prev" in -d|-h) diff --git a/lib/helpers.bash b/lib/helpers.bash index 9b95fe65..61705a04 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -449,7 +449,7 @@ _bash-it-restart() { _about 'restarts the shell in order to fully reload it' _group 'lib' - saved_pwd=$(pwd) + saved_pwd="${PWD}" case $OSTYPE in darwin*) diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index 5f27db01..2c1adf7a 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -23,7 +23,7 @@ alias 8="pushd +8" alias 9="pushd +9" # Clone this location -alias pc="pushd \$(pwd)" +alias pc='pushd "${PWD}"' # Push new location alias pu="pushd" @@ -73,7 +73,7 @@ G () { example '$ G ..' group 'dirs' - cd "${1:-$(pwd)}" ; + cd "${1:-${PWD}}" ; } S () { diff --git a/themes/powerturk/powerturk.theme.bash b/themes/powerturk/powerturk.theme.bash old mode 100644 new mode 100755 index 4590a8aa..3352f680 --- a/themes/powerturk/powerturk.theme.bash +++ b/themes/powerturk/powerturk.theme.bash @@ -43,7 +43,7 @@ _swd(){ begin="" # The unshortened beginning of the path. shortbegin="" # The shortened beginning of the path. current="" # The section of the path we're currently working on. - end="${2:-$(pwd)}/" # The unmodified rest of the path. + end="${2:-${PWD}}/" # The unmodified rest of the path. if [[ "$end" =~ "$HOME" ]]; then INHOME=1 From 8d1e802565d0e0b6d4f110c48984d5015a6c040f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 5 Sep 2021 17:35:05 -0700 Subject: [PATCH 14/14] test: Use `${PWD}` instead of `$(pwd)` --- test/plugins/base.plugin.bats | 2 +- test/run | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 7daf2619..1def481e 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -40,7 +40,7 @@ load ../../plugins/available/base.plugin mkcd "${dir_name}" assert_success assert_dir_exist "${BASH_IT_ROOT}/${dir_name}" - assert_equal $(pwd) "${BASH_IT_ROOT}/${dir_name}" + assert_equal "${PWD}" "${BASH_IT_ROOT}/${dir_name}" } @test 'plugins base: lsgrep()' { diff --git a/test/run b/test/run index 88202916..fe4ac847 100755 --- a/test/run +++ b/test/run @@ -6,7 +6,7 @@ git submodule init && git submodule update if [ -z "${BASH_IT}" ]; then declare BASH_IT - BASH_IT=$(cd ${test_directory} && dirname "$(pwd)") + BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" export BASH_IT fi