diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..317a217 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,19 @@ +name: reviewdog +on: + push: + branches-ignore: + - 'gh-pages' + +jobs: + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: shellcheck + uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check + path: "./commands/inits/data" + pattern: "*.sh" diff --git a/commands/inits/data/aliases.sh b/commands/inits/data/aliases.sh index c3201bc..dfdf3fe 100644 --- a/commands/inits/data/aliases.sh +++ b/commands/inits/data/aliases.sh @@ -1,3 +1,5 @@ +# source file: aliases.sh +# shellcheck shell=sh alias gs='scmpuff_status' alias ga='git add' alias gd='git diff' diff --git a/commands/inits/data/git_wrapper.sh b/commands/inits/data/git_wrapper.sh index 2c4c17a..403d35a 100644 --- a/commands/inits/data/git_wrapper.sh +++ b/commands/inits/data/git_wrapper.sh @@ -1,3 +1,6 @@ +# source file: git_wrapper.sh +# shellcheck shell=sh + # Remove any existing git alias or function unalias git > /dev/null 2>&1 unset -f git > /dev/null 2>&1 @@ -6,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" "$@";; diff --git a/commands/inits/data/status_shortcuts.sh b/commands/inits/data/status_shortcuts.sh index d22f6e9..3fdd991 100644 --- a/commands/inits/data/status_shortcuts.sh +++ b/commands/inits/data/status_shortcuts.sh @@ -1,53 +1,53 @@ +# source file: status_shortcuts.sh +# shellcheck shell=sh + scmpuff_status() { - local scmpuff_env_char="e" + __scmpuff_env_char="e" # Ensure shwordsplit is on for zsh if [ -n "$ZSH_VERSION" ]; then setopt shwordsplit; fi; # 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 $@)" + __scmpuff_status_cmd_output=$(/usr/bin/env scmpuff status --filelist "$@") + __scmpuff_status_exit=$? # 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) - local es=$? - if [ $es -ne 0 ]; then - return $es + if [ $__scmpuff_status_exit -ne 0 ]; then + return $__scmpuff_status_exit fi # Fetch list of files (from first line of script output) - files="$(echo "$cmd_output" | head -n 1)" + __scmpuff_files="$(echo "$__scmpuff_status_cmd_output" | head -n 1)" # Export numbered env variables for each file scmpuff_clear_vars - IFS=$'\t' - local e=1 - for file in $files; do - export $scmpuff_env_char$e="$file" - let e++ + IFS=$(printf '\t') + __scmpuff_loop_e=1 + for __scmpuff_file in $__scmpuff_files; do + export $__scmpuff_env_char$__scmpuff_loop_e="$__scmpuff_file" + __scmpuff_loop_e=$((__scmpuff_loop_e+1)) #e++ done - IFS=$' \t\n' + IFS=$(printf ' \t\n') # Print status (from line two onward) - echo "$cmd_output" | tail -n +2 + echo "$__scmpuff_status_cmd_output" | tail -n +2 # Reset zsh environment to default if [ -n "$ZSH_VERSION" ]; then unsetopt shwordsplit; fi; } - # 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 - unset ${env_var_i} + __scmpuff_env_char="e" + __scmpuff_loop_i=0 + while [ $__scmpuff_loop_i -le 999 ]; do + __scmpuff_env_var_i=${__scmpuff_env_char}${__scmpuff_loop_i} + if [ -n "$__scmpuff_env_var_i" ]; then + unset "$__scmpuff_env_var_i" else break fi + __scmpuff_loop_i=$((__scmpuff_loop_i+1)) #i++ done } diff --git a/features/command_init.feature b/features/command_init.feature index bb299f2..8a759db 100644 --- a/features/command_init.feature +++ b/features/command_init.feature @@ -26,7 +26,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 |