diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index d16d7c7..64cfee7 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -25,6 +25,12 @@ jobs: - name: run shellcheck anf shfmt shell: bash run: | - set -e - ./.helpers/sh-checks - ./.helpers/git-check-dirty + ./.helpers/shellcheck + + - name: shfmt + shell: bash + run: | + status=0 + ./.helpers/shfmt || status=1 + ./.helpers/git-check-dirty || status=1 + exit "${status}" diff --git a/.helpers/foreach-script b/.helpers/foreach-script index ca5f4ce..6f821b6 100755 --- a/.helpers/foreach-script +++ b/.helpers/foreach-script @@ -10,19 +10,24 @@ # -perm +111 +VERBOSE=${VERBOSE:="0"} + +mapfile -d '' -t files < <( + find ./ \ + -type f \ + -and \( -not -path './.git/*' \) \ + -and \( -not -path './vendor/*' \) \ + -and \( -name '*.bash' -or -name '*.sh' -or -executable \) \ + -print0 +) + status=0 -find ./ \ - -type f \ - -and \( -not -path './.git/*' \) \ - -and \( -not -path './vendor/*' \) \ - -and \( -name '*.bash' -or -name '*.sh' -or -executable \) \ - -print0 | while IFS= read -r -d '' file; do + +for file in "${files[@]}"; do if file "${file}" | grep -qE 'shell script|POSIX shell script|Bourne-Again shell script|bash script|a sh script'; then - echo "${*} ${file}" - if ! "${@}" "${file}"; then - status=1 - fi + [[ ${VERBOSE} == "1" ]] || echo "${*} ${file}" + "${@}" "${file}" || status=1 fi done -exit $status +exit ${status} diff --git a/.helpers/sh-checks b/.helpers/sh-checks deleted file mode 100755 index edbb2c0..0000000 --- a/.helpers/sh-checks +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -e -#set -u -set -o pipefail - -# should be called from root dir. - -./.helpers/foreach-script shfmt --simplify --language-dialect auto --case-indent --indent 2 --write -./.helpers/foreach-script shellcheck \ - --norc \ - --external-sources \ - --format=tty \ - --enable=require-variable-braces,add-default-case \ - --exclude=SC2012 \ - --exclude=SC2002 \ - --exclude=SC2059 \ - --exclude=SC2181 - -# SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames. https://www.shellcheck.net/wiki/SC2012 -# SC2059 (info): Don't use variables in the printf format string. https://www.shellcheck.net/wiki/SC2059 -# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. https://www.shellcheck.net/wiki/SC2002 -# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181 diff --git a/.helpers/shellcheck b/.helpers/shellcheck index 13e4479..5f9ffb8 100755 --- a/.helpers/shellcheck +++ b/.helpers/shellcheck @@ -5,22 +5,18 @@ if ! command -v shellcheck &>/dev/null; then exit 1 fi -mapfile -t FILES < <(find . \ - \( -not -name 'root.bash' \) \ - -a \( -not -path './.git/*' \) \ - -a \( -not -path './config/gnome/lib/palettes/*' \) \ - -a \( -name '*.bash' -o \( -type f -a -executable \) \) \ - -print) - -set -x - -shellcheck \ - --shell=bash \ - --exclude=SC1090 \ +./.helpers/foreach-script shellcheck \ + --norc \ --external-sources \ - --severity=warning \ --format=tty \ - --source-path=./config/gnome/lib \ - --norc \ - root.bash \ - "${FILES[@]}" + --enable=require-variable-braces,add-default-case \ + --exclude=SC2012 \ + --exclude=SC2002 \ + --exclude=SC2059 \ + --exclude=SC2181 + +# SC2012 (info): Use find instead of ls to better handle non-alphanumeric filenames. https://www.shellcheck.net/wiki/SC2012 +# SC2059 (info): Don't use variables in the printf format string. https://www.shellcheck.net/wiki/SC2059 +# SC2002 (style): Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. https://www.shellcheck.net/wiki/SC2002 +# SC2181 (style): Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181 + diff --git a/.helpers/shfmt b/.helpers/shfmt new file mode 100644 index 0000000..0a5d15f --- /dev/null +++ b/.helpers/shfmt @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if ! command -v shfmt &>/dev/null; then + echo 'shfmt not found' >&2 + exit 1 +fi + +./.helpers/foreach-script shfmt \ + --simplify \ + --language-dialect auto \ + --case-indent \ + --indent 2 \ + --write diff --git a/install b/install index 73af890..fd2ce97 100755 --- a/install +++ b/install @@ -14,6 +14,7 @@ path-read-link() { ;; *) readlink -n "${1}" + ;; esac }