aboutsummaryrefslogtreecommitdiffstats
path: root/.config/sxiv/exec/key-handler
blob: 927ca03965987d61e7e306184253d5a59e13a435 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/zsh

source ~/.config/init/vars

# The key combo argument has the following form: "[C-][M-][S-]KEY",
# where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
# keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.

files=()
while read line; do
	files=( "${files[@]}" "$line" )
done

if [[ "${#files[@]}" -eq 1 ]]; then
	case "$1" in
		"y")
			echo -n "$files" | xclip -selection clipboard
			echo -n "$files" | xclip -selection primary
			exit
			;;
		"r")
			dmenu "${dmenu_args[@]}" -q -noinput
			exit
			;;
		*) ;;
	esac
fi

case "$1" in
	"C-d") rm "${files[@]}" ;;
	"g") gimp "${files[@]}" & ;;
	"k") krita "${files[@]}" & ;;
	"i") inkscape "${files[@]}" & ;;
	"s")
		send "${files[@]}"
		if [[ $? -ne 0 ]]; then
			notify-send "sxiv: send to /tmp/ failed"
		else
			if [[ ${#files} -eq 1 ]]; then
				notify-send "sxiv: sent ${files:t} to /tmp/"
			else
				notify-send "sxiv: sent ${#files} images to /tmp/"
			fi
		fi
		;;
	*)
		notify-send "sxiv: command not recognised" ;;
esac