diff options
author | zachir <zachir@librem.one> | 2025-08-30 01:09:18 -0500 |
---|---|---|
committer | zachir <zachir@librem.one> | 2025-08-30 01:09:18 -0500 |
commit | f28d694879239d5d9c319185a278236d317a49b6 (patch) | |
tree | 3f684e05c6372c8f0fc0b9f126a184f3aaad68d4 /scrshot | |
parent | 7d3cbe8f708772e40608260590b717dea6735908 (diff) |
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.
Diffstat (limited to 'scrshot')
-rwxr-xr-x | scrshot | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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!" |