From 7c3a0a4f09c81558918b66deeafa486234a73294 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 20 Oct 2022 11:07:19 -0300 Subject: Fix all ShellCheck warnings IOW, `make check-shellcheck` passes. --- bin/backup | 2 ++ bin/bins | 4 +++- bin/boop | 2 +- bin/cl | 26 +++++++++++++++----------- bin/color | 1 + bin/dice | 9 ++++++++- bin/grun | 2 ++ bin/httpno | 8 +++++++- bin/lines | 2 +- bin/menu | 8 +++++++- bin/msg | 1 - bin/yt | 3 +++ etc/sh/cronjob.sh | 1 + etc/sh/rc | 1 + etc/sh/vcs-ps1.sh | 2 +- 15 files changed, 53 insertions(+), 19 deletions(-) diff --git a/bin/backup b/bin/backup index 0ebef43..be7d996 100755 --- a/bin/backup +++ b/bin/backup @@ -93,6 +93,8 @@ ARCHIVE_TAG="${1:-manual}" run() { set -x + # The contents of $VERBOSE_FLAGS doesn't involve user input: + # shellcheck disable=2086 borg create \ $VERBOSE_FLAGS \ --comment "$COMMENT" \ diff --git a/bin/bins b/bin/bins index 28e92f1..710cf8a 100755 --- a/bin/bins +++ b/bin/bins @@ -64,8 +64,10 @@ shift $((OPTIND- 1)) F="$XDG_CACHE_HOME/euandreh/bins" IFS=: +# Word-splitting is the goal: +# shellcheck disable=2086 if stest -rdq -n "$F" $PATH; then - trap "rm -f $F-tmp" EXIT + trap 'rm -f $F-tmp' EXIT stest -lxf $PATH | sort -u > "$F"-tmp mv "$F"-tmp "$F" fi diff --git a/bin/boop b/bin/boop index d2de30f..a7792b3 100755 --- a/bin/boop +++ b/bin/boop @@ -77,7 +77,7 @@ else N=1 fi -CMD="$@" +CMD="$*" msg -"$N" -bs -D "${MESSAGE:-$CMD}" exit "$STATUS" diff --git a/bin/cl b/bin/cl index 77f6fb6..a38d00a 100755 --- a/bin/cl +++ b/bin/cl @@ -187,6 +187,7 @@ for f in "$@"; do INTERACTIVE=false escape_name "$f" >> "$SCRIPT" done +set -- MAIN="$(mkstemp)" if [ "$NO_RC" = false ] && [ -e "$LISP_CLI_RC" ]; then @@ -217,7 +218,7 @@ if [ -z "$IMPL" ]; then fi done if [ -z "$IMPL" ]; then - printf 'Could not find any implementation in $PATH.\n' >&2 + printf "Could not find any implementation in \$PATH.\n" >&2 exit 2 fi fi @@ -228,6 +229,7 @@ if [ "$SKIP_DEFAULT_IMAGE" = false ] && [ -z "$IMAGE" ] && IMAGE="$DEFAULT_IMAGE" fi + case "$IMPL" in abcl) exit 4 @@ -242,19 +244,19 @@ case "$IMPL" in exit 4 ;; clisp) - ARGS="-ansi -i $MAIN" + set -- -ansi -i "$MAIN" if [ -n "$IMAGE" ]; then - set -- -M "$IMAGE" + set -- "$@" -M "$IMAGE" fi if [ "$NO_RC" = true ]; then - ARGS="$ARGS -norc" + set -- "$@" -norc fi if [ "$VERBOSE" = false ]; then - ARGS="$ARGS -q -q" + set -- "$@" -q -q else set -x fi - exec clisp $ARGS "$@" + exec clisp "$@" ;; cmucl) exit 4 @@ -269,19 +271,21 @@ case "$IMPL" in exit 4 ;; sbcl) - ARGS="--load $MAIN" + set -- --load "$MAIN" if [ -n "$IMAGE" ]; then - set -- --core "$IMAGE" + # The '--core' "C runtime option" must appear before the + # other "Lisp options", such as '--load'. + set -- --core "$IMAGE" "$@" fi if [ "$NO_RC" = true ]; then - ARGS="$ARGS --no-sysinit --no-userinit" + set -- "$@" --no-sysinit --no-userinit fi if [ "$VERBOSE" = false ]; then - ARGS="--noinform $ARGS" + set -- "$@" --noinform else set -x fi - exec sbcl "$@" $ARGS + exec sbcl "$@" ;; *) printf 'Unsupported implementation: "%s".\n\n' "$IMPL" >&2 diff --git a/bin/color b/bin/color index 05ef95b..dc610e9 100755 --- a/bin/color +++ b/bin/color @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck disable=2059 set -eu usage() { diff --git a/bin/dice b/bin/dice index 93556a5..4a145d0 100755 --- a/bin/dice +++ b/bin/dice @@ -18,15 +18,21 @@ help() { SIZE the size of the dice (default: 6) + Roll a dice of SIZE. Caveat: rolling a dice more than once in + the same second will give you the same number. + + Examples: Roll a dice of size 6: $ dice + 3 Roll a D20: $ dice 20 + 15 EOF } @@ -63,4 +69,5 @@ shift $((OPTIND - 1)) SIZE="${1:-6}" -echo $(((RANDOM % SIZE) + 1)) +RAND="$(awk 'BEGIN { srand(); print int(rand()*32768) }' /dev/null)" +echo $(((RAND % SIZE) + 1)) diff --git a/bin/grun b/bin/grun index 982420a..74d8819 100755 --- a/bin/grun +++ b/bin/grun @@ -91,4 +91,6 @@ else OUT="$(gpg -dq "$FILENAME" | "$@")" fi +# GPG recipients can't contain spaces: +# shellcheck disable=2086 echo "$OUT" | gpg -e ${RECIPIENTS_FLAG:--r eu@euandre.org} | sponge "$FILENAME" diff --git a/bin/httpno b/bin/httpno index 0e8d66f..e64b872 100755 --- a/bin/httpno +++ b/bin/httpno @@ -45,7 +45,8 @@ help() { } DATA() { - awk 'd == 1 { print; next } /^__DATA__$/ { d = 1 }' "$0" + awk 'd == 1 { print; next } /^__DATA__$/ { d = 1 }' "$0" | + head -n -1 # trim ShellCheck quote } @@ -88,6 +89,10 @@ fi exit + +# Make ShellCheck happy. See https://github.com/koalaman/shellcheck/issues/1201 +# shellcheck disable=1112 +echo " __DATA__ 100 Continue 101 Switching Protocols @@ -148,3 +153,4 @@ __DATA__ 509 Bandwidth Limit Exceeded 510 Not Extended 511 Network Authentication Required +" diff --git a/bin/lines b/bin/lines index b2558b8..2f0bf46 100755 --- a/bin/lines +++ b/bin/lines @@ -73,7 +73,7 @@ START="${1:-}" if [ -z "${2:-}" ]; then END=1 else - END=$(($2 - $START + 1)) + END=$(($2 - START + 1)) fi eval "$(assert-arg "$START" 'START')" diff --git a/bin/menu b/bin/menu index 9f1fe09..94e124f 100755 --- a/bin/menu +++ b/bin/menu @@ -76,7 +76,8 @@ eval "$(assert-arg "$ACTION" 'ACTION')" DATA() { - awk 'd == 1 { print; next } /^__DATA__$/ { d = 1 }' "$0" + awk 'd == 1 { print; next } /^__DATA__$/ { d = 1 }' "$0" | + head -n -1 # trim ShellCheck quote } show() { @@ -144,6 +145,10 @@ esac exit + +# Make ShellCheck happy. See https://github.com/koalaman/shellcheck/issues/1201 +# shellcheck disable=1112 +echo ' __DATA__ grinning face πŸ˜€ smiling face with open mouth πŸ˜ƒ @@ -1577,3 +1582,4 @@ Western Sahara πŸ‡ͺπŸ‡­ Yemen πŸ‡ΎπŸ‡ͺ Zambia πŸ‡ΏπŸ‡² Zimbabwe πŸ‡ΏπŸ‡Ό +' diff --git a/bin/msg b/bin/msg index f685ffb..b2a6794 100755 --- a/bin/msg +++ b/bin/msg @@ -68,7 +68,6 @@ MAIL=false DESKTOP=false BELL=false ACTION_DONE=false -SHOW_USAGE=false while getopts '01XsSmDbh' flag; do case "$flag" in 0) diff --git a/bin/yt b/bin/yt index ddcc02d..d0ff37e 100755 --- a/bin/yt +++ b/bin/yt @@ -100,6 +100,9 @@ if [ -z "${FORCE:-}" ]; then EXTRA_OPTIONS="--download-archive $HOME/Downloads/yt-dl/seen.txt" fi +# The value of $EXTRA_OPTIONS doesn't depend on user input, and can't contain +# spaces, unless $HOME contains spaces: +# shellcheck disable=2086 youtube-dl \ --batch-file "$F" \ --format best \ diff --git a/etc/sh/cronjob.sh b/etc/sh/cronjob.sh index 1e11b50..05022e0 100755 --- a/etc/sh/cronjob.sh +++ b/etc/sh/cronjob.sh @@ -65,6 +65,7 @@ done shift $((OPTIND - 1)) +# shellcheck disable=1090 . ~/.usr/etc/sh/rc CMD="$*" with-email -s "$CMD" -- "$@" 1>>"$XDG_LOG_HOME"/euandreh/mcron.log 2>&1 diff --git a/etc/sh/rc b/etc/sh/rc index d5801b8..69606fa 100644 --- a/etc/sh/rc +++ b/etc/sh/rc @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck disable=1090,1091 export ENV=~/.profile diff --git a/etc/sh/vcs-ps1.sh b/etc/sh/vcs-ps1.sh index b9a849a..7cc528d 100644 --- a/etc/sh/vcs-ps1.sh +++ b/etc/sh/vcs-ps1.sh @@ -128,7 +128,7 @@ shell_status_level() { } shell_status_jobs() { - JOBS="$(jobs | grep -v autojump | wc -l)" + JOBS="$(jobs | grep -c autojump)" if [ "$JOBS" != 0 ]; then color -c red "$JOBS" fi -- cgit v1.2.3