Krolyxon
Commit c1e0843

Branches

Refs →

nsxivexeckey-handler

52 lines · 1.6 KB · Bourne Again Shell (bash)

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
14readonly KEY="$1"; shift
15readonly TAGFILE="$HOME/.config/sxiv/tags"
16
17rotate() {
18 degree="$1"; shift
19 for file in "$@"; do
20 case "$(file -b -i "$file")" in
21 image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;;
22 *) mogrify -rotate "$degree" "$file" ;;
23 esac
24 done
25}
26
27tag_add() {
28 >>"$TAGFILE"
29 tags=$(dmenu <"$TAGFILE" | tr '\n' ',')
30 [ -z "$tags" ] && return
31 iptckwed -a "$tags" "$@"
32 echo -n "$tags" | tr ',' '\n' | sort - "$TAGFILE" | uniq >"$TAGFILE.new"
33 mv -f "$TAGFILE"{.new,}
34}
35
36tag_del() {
37 tags=$(iptckwed -ql "$@" | cut -f 2 | tr ',' '\n' | sort | uniq | dmenu | tr '\n' ',')
38 [ -z "$tags" ] && return
39 iptckwed -r "$tags" "$@"
40}
41
42case "$KEY" in
43"C-c") echo -n "$@" | xsel -i ;;
44"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 ;;
45"C-g") gimp "$@" & ;;
46"C-comma") rotate 270 "$@" ;;
47"C-period") rotate 90 "$@" ;;
48"C-slash") rotate 180 "$@" ;;
49"C-t") tag_add "$@" ;;
50"M-T") tag_del "$@" ;;
51esac
52