From c955b1011c2980fb8f039131fde20cc8cf6bcc0f Mon Sep 17 00:00:00 2001 From: Matthew Rothenberg Date: Sun, 5 Dec 2021 20:09:18 -0500 Subject: [PATCH] fix(init): address shellcheck recommendations --- commands/inits/data/git_wrapper.sh | 5 +++-- commands/inits/data/status_shortcuts.sh | 20 +++++++++++--------- features/command_init.feature | 2 +- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/commands/inits/data/git_wrapper.sh b/commands/inits/data/git_wrapper.sh index 51bd2eb..db8f8ca 100644 --- a/commands/inits/data/git_wrapper.sh +++ b/commands/inits/data/git_wrapper.sh @@ -6,12 +6,13 @@ unalias git > /dev/null 2>&1 unset -f git > /dev/null 2>&1 # Use the full path to git to avoid infinite loop with git function -export SCMPUFF_GIT_CMD="$(\which git)" +SCMPUFF_GIT_CMD="$(\which git)" +export SCMPUFF_GIT_CMD # Wrap git with the 'hub' github wrapper, if installed if type hub > /dev/null 2>&1; then export SCMPUFF_GIT_CMD="hub"; fi -function git() { +git() { case $1 in commit|blame|log|rebase|merge) scmpuff exec -- "$SCMPUFF_GIT_CMD" "$@";; diff --git a/commands/inits/data/status_shortcuts.sh b/commands/inits/data/status_shortcuts.sh index b6a2c38..ec01d9c 100644 --- a/commands/inits/data/status_shortcuts.sh +++ b/commands/inits/data/status_shortcuts.sh @@ -9,7 +9,7 @@ scmpuff_status() { # Run scmpuff status, store output # (`local` needs to be on its own line otherwise exit code is swallowed!) local cmd_output - cmd_output="$(/usr/bin/env scmpuff status --filelist $@)" + cmd_output=$(/usr/bin/env scmpuff status --filelist "$@") # if there was an error, exit prematurely, and pass along the exit code # (STDOUT was swallowed but not STDERR, so user should still see error msg) @@ -19,17 +19,19 @@ scmpuff_status() { fi # Fetch list of files (from first line of script output) + local files files="$(echo "$cmd_output" | head -n 1)" # Export numbered env variables for each file scmpuff_clear_vars - IFS=$'\t' + IFS=$(printf '\t') local e=1 + local file for file in $files; do export $scmpuff_env_char$e="$file" - let e++ + e=$((e+1)) done - IFS=$' \t\n' + IFS=$(printf ' \t\n') # Print status (from line two onward) echo "$cmd_output" | tail -n +2 @@ -42,14 +44,14 @@ scmpuff_status() { # Clear numbered env variables scmpuff_clear_vars() { local scmpuff_env_char="e" - local i - - for (( i=1; i<=999; i++ )); do - local env_var_i=${scmpuff_env_char}${i} - if [[ -n ${env_var_i} ]]; then + local i=0 + while [ $i -le 999 ]; do + env_var_i=${scmpuff_env_char}${i} + if [ -n "$env_var_i" ]; then unset ${env_var_i} else break fi + i=$((i+1)) done } diff --git a/features/command_init.feature b/features/command_init.feature index f12e024..9517990 100644 --- a/features/command_init.feature +++ b/features/command_init.feature @@ -21,7 +21,7 @@ Feature: init command Scenario Outline: --wrap controls git cmd wrapping in output (default: yes) When I successfully run `scmpuff init ` - Then the output contain "function git()" + Then the output contain "git() {" Examples: | flags | should? | | -s | should |