key-handler 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. # Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler
  3. # Called by sxiv(1) after the external prefix key (C-x by default) is pressed.
  4. # The next key combo is passed as its first argument. Passed via stdin are the
  5. # images to act upon, one path per line: all marked images, if in thumbnail
  6. # mode and at least one image has been marked, otherwise the current image.
  7. # sxiv(1) blocks until this script terminates. It then checks which images
  8. # have been modified and reloads them.
  9. # The key combo argument has the following form: "[C-][M-][S-]KEY",
  10. # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
  11. # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
  12. rotate() {
  13. degree="$1"
  14. tr '\n' '\0' | xargs -0 realpath | sort | uniq | while read file; do
  15. case "$(file -b -i "$file")" in
  16. image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;;
  17. *) mogrify -rotate "$degree" "$file" ;;
  18. esac
  19. done
  20. }
  21. case "$1" in
  22. "C-x") xclip -in -filter | tr '\n' ' ' | xclip -in -selection clipboard ;;
  23. "C-c") while read file; do convert "$file" png:- | xclip -selection clipboard -target "image/png"; done ;;
  24. "C-e") while read file; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 pr -q -pa '$file' | less" & done ;;
  25. "C-g") tr '\n' '\0' | xargs -0 gimp & ;;
  26. "C-r") while read file; do rawtherapee "$file" & done ;;
  27. "C-comma") rotate 270 ;;
  28. "C-period") rotate 90 ;;
  29. "C-slash") rotate 180 ;;
  30. "C-t") tr '\n' '\0' | xargs -0 img-chon.sh tag-dmenu
  31. esac