From 973ea984c8708f477573d9f3ffcf7387dd92f4ef Mon Sep 17 00:00:00 2001 From: VeryTastyTomato <8625408+VeryTastyTomato@users.noreply.github.com> Date: Sun, 29 Nov 2020 23:41:18 +0100 Subject: [PATCH] fix: warnings of ShellCheck SC2155: Declare and assign separately to avoid masking return values. SC2164: Use cd ... || exit in case cd fails. SC2230: which is non-standard. Use builtin 'command -v' instead. --- diagnostics/info.sh | 10 ++++++---- tests/benchmarks/comparison.sh | 4 ++-- tests/benchmarks/run-benchmarks.sh | 4 ++-- tests/syntax-tests/update.sh | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/diagnostics/info.sh b/diagnostics/info.sh index bf4eb4d8..b8d99983 100755 --- a/diagnostics/info.sh +++ b/diagnostics/info.sh @@ -58,7 +58,8 @@ _bat_:run() { _out "$BAT" --version _out env | grep '^BAT_\|^PAGER=' - local cache_dir="$($BAT --cache-dir)" + local cache_dir + cache_dir="$($BAT --cache-dir)" if [[ -f "${cache_dir}/syntaxes.bin" ]]; then _print_command "$BAT" "--list-languages" echo "Found custom syntax set." @@ -79,8 +80,8 @@ _bat_config_:run() { _bat_wrapper_:run() { _bat_wrapper_:detect_wrapper() { local bat="$1" - if file "$(which "${bat}")" | grep "text executable" &> /dev/null; then - _out_fence cat "$(which "${bat}")" + if file "$(command -v "${bat}")" | grep "text executable" &> /dev/null; then + _out_fence cat "$(command -v "${bat}")" return fi @@ -104,7 +105,8 @@ _bat_wrapper_function_:run() { fi ;; *bash* | *zsh*) - local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)" + local type + type="$("$SHELL" --login -i -c "type ${command}" 2>&1)" if grep 'function' <<< "$type" &> /dev/null; then _out_fence "$SHELL" --login -i -c "declare -f ${command}" return diff --git a/tests/benchmarks/comparison.sh b/tests/benchmarks/comparison.sh index c9eb5237..be1479e6 100755 --- a/tests/benchmarks/comparison.sh +++ b/tests/benchmarks/comparison.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -cd "$(dirname "${BASH_SOURCE[0]}")" +cd "$(dirname "${BASH_SOURCE[0]}")" || exit -if ! which hyperfine > /dev/null 2>&1; then +if ! command -v hyperfine > /dev/null 2>&1; then echo "'hyperfine' does not seem to be installed." echo "You can get it here: https://github.com/sharkdp/hyperfine" exit 1 diff --git a/tests/benchmarks/run-benchmarks.sh b/tests/benchmarks/run-benchmarks.sh index c3a15509..f74bdf24 100755 --- a/tests/benchmarks/run-benchmarks.sh +++ b/tests/benchmarks/run-benchmarks.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -cd "$(dirname "${BASH_SOURCE[0]}")" +cd "$(dirname "${BASH_SOURCE[0]}")" || exit -if ! which hyperfine > /dev/null 2>&1; then +if ! command -v hyperfine > /dev/null 2>&1; then echo "'hyperfine' does not seem to be installed." echo "You can get it here: https://github.com/sharkdp/hyperfine" exit 1 diff --git a/tests/syntax-tests/update.sh b/tests/syntax-tests/update.sh index b4752f05..8db1f3d5 100755 --- a/tests/syntax-tests/update.sh +++ b/tests/syntax-tests/update.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -cd "$(dirname "${BASH_SOURCE[0]}")" +cd "$(dirname "${BASH_SOURCE[0]}")" || exit python="python3" if ! command -v python3 &>/dev/null; then python="python"; fi