Debian Codegraph @

etc/examples/key-handler

raw
1 #!/bin/sh
2
3 # Example for $XDG_CONFIG_HOME/nsxiv/exec/key-handler
4 # Called by nsxiv(1) after the external prefix key (C-x by default) is pressed.
5 # The next key combo is passed as its first argument. Passed via stdin are the
6 # images to act upon: all marked images, if in thumbnail mode and at least one
7 # image has been marked, otherwise the current image. nsxiv(1) will block until
8 # the handler terminates. It then checks which images have been modified and
9 # reloads them.
10
11 # The key combo argument has the following form: "[C-][M-][S-]KEY",
12 # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
13 # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
14 # If KEY has an uppercase equivalent, S-KEY is resolved into it. For instance,
15 # K replaces S-k and Scedilla replaces S-scedilla, but S-Delete is sent as-is.
16
17 # By default nsxiv(1) will send one image per-line to stdin, however when using
18 # -0 the image list will be NULL separated and the environment variable
19 # "$NSXIV_USING_NULL" will be set to 1.
20
21 [ "$NSXIV_USING_NULL" = 1 ] && DELIM='\0' || DELIM='\n'
22
23 rotate() {
24 tr "$DELIM" '\0' | xargs -0 realpath -z | sort -z -u | xargs -0 -I {} sh -c '
25 degree="$1"
26 case "$(file -b -i "{}")" in
27 image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "{}" "{}" ;;
28 *) mogrify -rotate "$degree" "{}" ;;
29 esac
30 ' -- "$1"
31 }
32
33 case "$1" in
34 "C-x") xclip -in -filter | tr '\n' ' ' | xclip -in -selection clipboard ;;
35 "C-c") while read file; do xclip -selection clipboard -target image/png "$file"; done ;;
36 "C-e") while read file; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 -q -pa pr '$file' | less" & done ;;
37 "C-g") tr '\n' '\0' | xargs -0 gimp & ;;
38 "C-r") while read file; do rawtherapee "$file" & done ;;
39 "C-comma") rotate 270 ;;
40 "C-period") rotate 90 ;;
41 "C-slash") rotate 180 ;;
42 esac
43