Skip to content

Commit

Permalink
fix: warnings of ShellCheck
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
VeryTastyTomato authored and sharkdp committed Dec 21, 2020
1 parent 60e00d4 commit 973ea98
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions diagnostics/info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmarks/comparison.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmarks/run-benchmarks.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/syntax-tests/update.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 973ea98

Please sign in to comment.