Skip to content

Commit

Permalink
fix(init): address shellcheck recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Dec 16, 2021
1 parent a01f34c commit 8f6b450
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion commands/inits/data/git_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ unset -f git > /dev/null 2>&1
SCMPUFF_GIT_CMD=${SCMPUFF_GIT_CMD:-"$(\which git)"}
export SCMPUFF_GIT_CMD

function git() {
git() {
case $1 in
commit|blame|log|rebase|merge)
scmpuff exec -- "$SCMPUFF_GIT_CMD" "$@";;
Expand Down
20 changes: 11 additions & 9 deletions commands/inits/data/status_shortcuts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion features/command_init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: init command

Scenario Outline: --wrap controls git cmd wrapping in output (default: yes)
When I successfully run `scmpuff init <flags>`
Then the output <should?> contain "function git()"
Then the output <should?> contain "git() {"
Examples:
| flags | should? |
| -s | should |
Expand Down

0 comments on commit 8f6b450

Please sign in to comment.