diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e0eb6ef..4817d12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,7 @@ jobs: - name: Install tools run: | sudo apt-get update - sudo apt-get install -y shellcheck devscripts + sudo apt-get install -y shellcheck devscripts shfmt - name: Run shellcheck run: shellcheck wcurl tests/* @@ -56,6 +56,9 @@ jobs: - name: Run checkbashisms run: checkbashisms wcurl tests/* + - name: Run shfmt + run: shfmt --func-next-line --space-redirects --case-indent --binary-next-line --indent 4 --posix --diff . + debian: name: debian runs-on: ubuntu-latest diff --git a/tests/tests.sh b/tests/tests.sh index 3ea80dd..71d6342 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -32,7 +32,8 @@ export PATH="${ROOTDIR}:${PATH}" readonly WCURL_CMD="wcurl --dry-run " -oneTimeSetUp() { +oneTimeSetUp() +{ if ! assertContains "Check compatibility" "test" "test"; then echo "Error: shunit2 version 2.1.8 or higher is required." echo "Please install a compatible version of shunit2." diff --git a/wcurl b/wcurl index 643ac31..e4a56e2 100755 --- a/wcurl +++ b/wcurl @@ -133,7 +133,7 @@ sanitize() is_subset_of() { case "${1}" in - *[!${2}]*|'') return 1;; + *[!${2}]* | '') return 1 ;; esac } @@ -151,9 +151,9 @@ percent_decode() decode_out="${decode_out}${decode_hex2}" # Skip decoding if this is a control character (00-1F). # Skip decoding if DECODE_FILENAME is not "true". - if is_subset_of "${decode_hex1}" "23456789abcdefABCDEF" && \ - is_subset_of "${decode_hex2}" "0123456789abcdefABCDEF" && \ - [ "${DECODE_FILENAME}" = "true" ]; then + if is_subset_of "${decode_hex1}" "23456789abcdefABCDEF" \ + && is_subset_of "${decode_hex2}" "0123456789abcdefABCDEF" \ + && [ "${DECODE_FILENAME}" = "true" ]; then # Use printf to decode it into octal and then decode it to the final format. decode_out="$(printf "%b" "\\$(printf %o "0x${decode_hex1}${decode_hex2}")")" fi @@ -171,7 +171,7 @@ get_url_filename() # If what remains contains a slash, there's a path; return it percent-decoded. case "${hostname_and_path}" in # sed to remove everything preceding the last '/', e.g.: "example/something" becomes "something" - */*) percent_decode "$(printf %s "${hostname_and_path}" | sed -e 's,^.*/,,')";; + */*) percent_decode "$(printf %s "${hostname_and_path}" | sed -e 's,^.*/,,')" ;; esac # No slash means there was just a hostname and no path; return empty string. } @@ -268,13 +268,13 @@ while [ -n "${1-}" ]; do OUTPUT_PATH="${opt}" ;; - -o|-O|--output) + -o | -O | --output) shift HAS_USER_SET_OUTPUT="true" OUTPUT_PATH="${1}" ;; - -o*|-O*) + -o* | -O*) opt=$(printf "%s\n" "${1}" | sed 's/^-[oO]//') HAS_USER_SET_OUTPUT="true" OUTPUT_PATH="${opt}" @@ -284,12 +284,12 @@ while [ -n "${1-}" ]; do DECODE_FILENAME="false" ;; - -h|--help) + -h | --help) usage exit 0 ;; - -V|--version) + -V | --version) print_version exit 0 ;;