| 1 | #!/bin/sh |
| 2 | |
| 3 | # Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler |
| 4 | # Called by sxiv(1) after the external prefix key (C-x by default) is pressed. |
| 5 | # The next key combo is passed as its first argument, followed by the paths of |
| 6 | # all marked images or the path of the current image, if no image is marked. |
| 7 | # sxiv(1) blocks until this script terminates. It then checks which images |
| 8 | # have been modified and reloads them. |
| 9 | |
| 10 | # The key combo argument has the following form: "[C-][M-][S-]KEY", |
| 11 | # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X |
| 12 | # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix. |
| 13 | |
| 14 | readonly TAGFILE="$HOME/.config/sxiv/tags" |
| 15 | |
| 16 | rotate() { |
| 17 | case "$(file -b -i "$2")" in |
| 18 | image/jpeg*) jpegtran -rotate "$1" -copy all -outfile "$2" "$2" ;; |
| 19 | *) mogrify -rotate "$1" "$2" ;; |
| 20 | esac |
| 21 | } |
| 22 | |
| 23 | tag_add() { |
| 24 | >>"$TAGFILE" |
| 25 | tags=$(dmenu <"$TAGFILE" | tr '\n' ',') |
| 26 | [ -z "$tags" ] && return |
| 27 | iptckwed -a "$tags" "$@" |
| 28 | echo -n "$tags" | tr ',' '\n' | sort - "$TAGFILE" | uniq >"$TAGFILE.new" |
| 29 | mv -f "$TAGFILE"{.new,} |
| 30 | } |
| 31 | |
| 32 | tag_del() { |
| 33 | tags=$(iptckwed -ql "$@" | cut -f 2 | tr ',' '\n' | sort | uniq | dmenu | tr '\n' ',') |
| 34 | [ -z "$tags" ] && return |
| 35 | iptckwed -r "$tags" "$@" |
| 36 | } |
| 37 | |
| 38 | key="$1" |
| 39 | shift |
| 40 | |
| 41 | case "$key" in |
| 42 | "C-c") echo -n "$@" | xsel -i ;; |
| 43 | "C-e") for file in "$@"; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 pr -q -pa '$file' | less" & done ;; |
| 44 | "C-g") gimp "$@" & ;; |
| 45 | "C-comma") for file in "$@"; do rotate 270 "$file"; done ;; |
| 46 | "C-period") for file in "$@"; do rotate 90 "$file"; done ;; |
| 47 | "C-slash") for file in "$@"; do rotate 180 "$file"; done ;; |
| 48 | "C-t") tag_add "$@" ;; |
| 49 | "M-T") tag_del "$@" ;; |
| 50 | esac |
| 51 | |