From e6ff299df50fe5db6037a0800144a22e4157b2c6 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Thu, 20 Jan 2022 11:54:48 +0100 Subject: shellcheck --- README.md | 8 ++++++++ gromo | 14 +++++++------- install.sh | 2 +- shellcheck.sh | 9 +++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100755 shellcheck.sh diff --git a/README.md b/README.md index 51b1589..5ea674e 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,14 @@ Misc useful command line utilities. All of them are covered by the BSD-3 license I run them regularly on Gentoo, Alpine Linux and OpenBSD, so they should work on most UNIX-like systems. In the case of shell scripts, try to be as POSIX compliant as possible (WIP). +To symlink all tools to ~/.local/bin: + + $ ./install.sh + +To shellcheck all tools: + + $ ./shellcheck.sh + # Who Guillermo Ramos diff --git a/gromo b/gromo index e083e60..927afcc 100755 --- a/gromo +++ b/gromo @@ -109,11 +109,11 @@ EOF out+="\n" done - sortedout=$(printf "$out" | sort -t $FS -k 2 -rn) + sortedout=$(printf '%s' "$out" | sort -t $FS -k 2 -rn) if [ -n "$sortedout" ]; then while IFS=$FS read -r task dur gromos; do - echo -e "$task\n\t$gromos gromos, $(pp_seconds $dur)" - done <<<$sortedout + echo -e "$task\n\t$gromos gromos, $(pp_seconds "$dur")" + done <<<"$sortedout" fi fi fi @@ -123,7 +123,7 @@ parse_duration() { duration=$1 case ${duration:0,-1} in s) - echo ${duration%s} + echo "${duration%s}" ;; m) echo $((${duration%m} * 60)) @@ -205,7 +205,7 @@ while getopts "$optspec" optchar; do ;; esac done -shift $(($OPTIND - 1)) +shift $((OPTIND - 1)) if [ "$#" -eq 1 ]; then fulltask="$1" @@ -229,7 +229,7 @@ while true; do echo -ne "\r\033[K[** IN PROGRESS: $fulltask **] " echo "$fulltask" > "$STATE_FILE" - sleep $gromo_duration + sleep "$gromo_duration" echo idle > "$STATE_FILE" inc_subtask "$fulltask" @@ -239,6 +239,6 @@ while true; do exit 0 fi - (sleep $stop_duration && mpv --no-terminal "$DING_FILE") & + (sleep "$stop_duration" && mpv --no-terminal "$DING_FILE") & slock || exit done diff --git a/install.sh b/install.sh index e77299c..53bc811 100755 --- a/install.sh +++ b/install.sh @@ -1,3 +1,3 @@ #!/bin/sh -stow -v $(dirname $0) -t ~/.local/bin --ignore=$(basename $0) +stow -v "$(dirname "$0")" -t ~/.local/bin --ignore='.*.sh$' diff --git a/shellcheck.sh b/shellcheck.sh new file mode 100755 index 0000000..7c8dc6e --- /dev/null +++ b/shellcheck.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +find "$(dirname "$0")" -maxdepth 1 -type f -executable -exec \ + sh -c ' +if head -n1 "$1" | egrep -q "sh$"; then + echo "====== CHECKING $1 ======"; + shellcheck "$1"; +fi + ' shell {} \; -- cgit v1.2.3