commit 264d503d94f00898e1f5f15eaecff98f011bf890 parent 6f54b18413df7324ebaa0bf4937b3a786445ebb9 Author: Jacob R. Edwards <n/a> Date: Mon, 5 Dec 2022 15:37:53 -0600 Redo sxiv key handler script The changes made are summarized here: - Many commands added - Some commands removed - Use the shell to handle image names instead of xargs and thus - Use sh for running arbitrary commands instead of xargs - Heavily utilize X to convey information instead of file streams Diffstat:
| M | local/sxiv/config/sxiv/exec/key-handler | | | 50 | ++++++++++++++++++++++++++++++++++++++------------ |
1 file changed, 38 insertions(+), 12 deletions(-)
diff --git a/local/sxiv/config/sxiv/exec/key-handler b/local/sxiv/config/sxiv/exec/key-handler @@ -1,21 +1,47 @@ #!/bin/sh -e -# Copyright 2020, 2021 Jacob R. Edwards +# Copyright 2020-2022 Jacob R. Edwards # License: GPLv3 # # key-handler -- sxiv(1) key handling script -images=__LINES__ -image=$images - -args() { tr '\n' '\0' | xargs -0J "$images" "$@"; } +die() { + echo "$*" 1>&2 + print "$@" + exit 1 +} ask() test "$(printf 'n\ny\n' | dmenu -p "$1?")" = 'y' -die() { echo "$@" 1>&2; exit 1; } -read() dmenu -p "$1" < /dev/null +read() xinput "sxiv $1" +info() exiftool -f -d '%F' "$@" +print() herbe "${*:-$(cat)}" +last() { echo $images | tail -1; } + +infofmt='${filename} + File: ${mimetype} ${ImageWidth}x${ImageHeight}x[${BitsPerSample}] + Date: ${DateTimeOriginal} + Camera: ${model} (${make}) +Settings: f/${aperture} ${shutterSpeed}s ISO ${ISO} ${focalLength}' + +IFS=' +' +images="$(cat)" case "$1" in -(C-c) eval args "$(read command)";; # use $image or $images to access images -(C-m) args mv lines "$(read dir)";; -(C-w) setbg "$(tail -1)";; -(C-x) ask remove && args rm $images;; -(*) die "$1: Invalid command";; +(C-c) read command | sh -s $images ;; +(C-C) read command | sh -s $images | print ;; +(C-t) info -p '$DateTimeOriginal ($FileName)' $images | print & ;; +(C-i) info -d '%F %R %z' -p "$infofmt" $images | print & ;; +(C-x) (ask remove && rm $images) & ;; +(C-w) setbg $(last) & ;; +(C-s) sxiv -t $images & ;; +(C-r) darktable $images & ;; +(*) + die "Key '$1' not defined. Try one of the following:" \ + ' C-c Run command' \ + ' C-C Run command and show output' \ + ' C-t Show image timestamp' \ + ' C-i Display image information' \ + ' C-x Remove images' \ + ' C-w Set last image to background' \ + ' C-s Open images in sxiv' \ + ' C-r Open images in darktable' esac