commit 3f517eb83739940ca4895b0b422b79396b9c8122
parent 867c42f7f3687cc8f0f953db5167159070f752de
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun, 11 Oct 2020 22:33:06 +0200
shell: fix quoting issues in open(er)
Remember to `printf %q` when you need stuff quoted in a way that can be
reused as shell input.
Former-commit-id: 45fdc492a90b2270148addaaf222babd897c2558
Diffstat:
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/scripts/open b/scripts/open
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -x
 PARAMS=""
 while [ $(($#)) -ne 0 ]; do
   case "$1" in
@@ -20,7 +21,7 @@ while [ $(($#)) -ne 0 ]; do
       exit 1
       ;;
     *) # preserve positional arguments
-      PARAMS="$PARAMS $1"
+      { [ -z "$PARAMS" ] && PARAMS="$(printf '%q' "$1")"; }|| PARAMS="$PARAMS $(printf '%q' "$1")"
       shift
       ;;
   esac
diff --git a/scripts/opener b/scripts/opener
@@ -1,4 +1,5 @@
 #!/bin/sh
+set -x
 [ $# -gt 0 ] || { printf "File required in argument.\n" && exit 1; }
 case $(file --mime-type "$1" -bL) in
   text/*|application/json|inode/x-empty) $EDITOR "$1";;
@@ -6,5 +7,5 @@ case $(file --mime-type "$1" -bL) in
   application/epub*) setsid -f ebook-viewer "$1" >/dev/null 2>&1;;
   video/*) mpvq "$@";;
   audio/*) mpv --no-audio-display --no-video --volume=50 "$1";;
-  *) setsid -f open "$1" > /dev/null 2>&1;;
+  *) setsid -f open "$@" > /dev/null 2>&1;;
 esac