From f28d694879239d5d9c319185a278236d317a49b6 Mon Sep 17 00:00:00 2001 From: zachir Date: Sat, 30 Aug 2025 01:09:18 -0500 Subject: Make sh scrips POSIX compliant Using shellcheck, I went through all of them to make them standards compliant. I also tested as many as I could. --- scrshot | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'scrshot') diff --git a/scrshot b/scrshot index 8982b56..e400b8e 100755 --- a/scrshot +++ b/scrshot @@ -2,19 +2,30 @@ output_text () { notify-send "$1" "$2" - printf "$2\n" + printf "%s\n" "$2" } -while getopts "hwxd:s:o:" o; do case "${o}" in +printhelp () { + printf "scrshot: takes a screenshot and saves to a filename.\n" + printf "\tw) force wayland backend\n" + printf "\tx) force x backend\n" + printf "\td X) provide X as arg to dmenu\n" + printf "\ts X) provide X as arg to screenshot util\n" + printf "\to X) save file to X\n" + exit 1 +} + +while getopts "wxd:s:o:" o; do case "${o}" in w) SCRSH="grim" ;; x) SCRSH="maim" ;; - d) DARG="$OPTARG $DARG" ;; - s) SARG="$OPTARG $SARG" ;; + d) DARG="$OPTARG" ;; + s) SARG="$OPTARG" ;; o) FILENAME="$OPTARG" ;; + *) printhelp ;; esac done if [ -z "$SCRSH" ]; then @@ -34,10 +45,10 @@ TEMPNAME="$(mktemp -u | xargs basename)" TEMPFILE="${TEMPNAME#tmp.}.png" sleep 0.1 -"$SCRSH" $SARG "$TEMPFILE" +"$SCRSH" ${SARG:+"$SARG"} "$TEMPFILE" if [ -z "$FILENAME" ]; then - FILENAME="$(echo "$TEMPFILE" | dmenu $DARGS -p "What to name the file?")" + FILENAME="$(echo "$TEMPFILE" | dmenu ${DARG:+"$DARG"} -p "What to name the file?")" if [ -z "$FILENAME" ]; then rm -rf "$TEMPFILE" output_text "Deleted" "No filename selected, file deleted!" -- cgit v1.2.3