aboutsummaryrefslogtreecommitdiff
path: root/files/sxiv/key-handler
blob: dc13548920534a6176b3d43d53fbebf3025ce93a (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash

case "$1" in
	"s")
		width=$(echo "" | dmenu -p "Width of new files?")
		[ "$width" ] || exit 0
		height=$(echo "" | dmenu -p "Height of new files?")
		[ "$height" ] || exit 0
		modifier=""
		[ "$(printf "Yes\nNo" | dmenu -i -p "Maintain aspect ratio?")" = "No" ] && modifier="!"
		while read -r file
		do
			convert "$file" -resize "$width"x"$height""$modifier" "$width"x"$height""$modifier"_"$file"
		done ;;
	"y")
		text=""
		while read -r file
		do
			text="$text""$file""\n"
		done
		echo -en "$text" | xsel -ib  &&
		dunstify "$(xsel -ob) copied to clipboard" ;;
	"Y")
		text=""
		while read -r file
		do
			text="$text""$(readlink -f "$file")""\n"
		done
		echo -en "$text" | xsel -ib &&
		dunstify "$(xsel -ob) copied to clipboard" ;;
	"G")
		images=""
		tmpFolder="/tmp/sxiv/gifs/"
		mkdir -p "$tmpFolder"
		while read -r file
		do
			convert "$file" -resize 512x999999\> "$tmpFolder$file"
			images="$images $tmpFolder$file"
		done
		delay=$(echo "" | dmenu -p "Delay of GIF?")
		[ "$delay" ] || exit 0
		name=$(echo "" | dmenu -p "Name of GIF?")
		[ "$name" ] || exit 0
		convert -delay "$delay" -loop 0 $images "$name.gif"
		dunstify "Created $name.gif" ;;

	"h")
		dunstify "\
w: Set as wallpaper.                        .
r: Rotate clockwise.                        .
R: Rotate counter-clockwise.                .
f: Flop (horizontally).                     .
F: Flip (vertically).                       .
y: Yank filename to clipboard.              .
Y: Yank file path to clipboard.             .
i: Yank image to clipboard.                 .
d: Move file to litter.	                    .
n: Rename file.                             .
N: Open in a new instance of sxiv.          .
g: Open in gimp.                            .
G: Make a gif out of selected images.       .
s: Create new image with different size.    .
S: Search image online.                     .
c: Copy images to a chosen folder.          .
m: Move images to a chosen folder.          .
h: Show help.                               ." ;;
esac

while read -r file
do
	case "$1" in
	"w") setBG.sh "$file" ;;
	"W") wal.sh "$file" ;;
	"r")
		convert -rotate 90 "$file" "$file" &&
		dunstify "$file rotated clockwise" ;;
	"R")
		convert -rotate -90 "$file" "$file" &&
		dunstify "$file rotated counter-clockwise" ;;
	"f")
		convert -flop "$file" "$file" &&
		dunstify "$file flopped" ;;
	"F")
		convert -flip "$file" "$file" &&
		dunstify "$file flipped" ;;
	"d")
		rm.sh "$file" && dunstify -i "$file" "$file moved to litter." ;;
	"n")
		newname="$(dmenu -p "New name of $file?")"
		[ "$newname" ] && newname="$newname"'.'"${file##*.}" && [ "$(printf "No\nYes" | dmenu -i -p "Rename $file to $newname?")" = "Yes" ] && mv "$file" "$newname" && dunstify "$file renamed to $newname." ;;
	"N")
		sxiv -b "$file" & ;;
	"g")
		gimp "$file" & ;;
	"S")
		echo -n "$(readlink -f "$file")" | xsel -ib && dunstify "$(xsel -ob) copied to clipboard"
		$BROWSER "https://tineye.com/" ;;
	"i")
		xclip -selection clipboard -t image/png "$(readlink -f "$file")" && dunstify "$file copied to clipboard as image."
		;;
	"c")
		[ -z "$destdir" ] && destdir="$(selectPath.sh "Copy image(s) to:")"
		[ -z "$destdir" ] && exit
		replace="Yes"
		if [ -e "$destdir""$file" ]; then
			dunstify -i "$destdir""$file" "Old:"
			dunstify -i "$(readlink -f "$file")" "New:"
			replace="$(echo -e "No\nYes" | dmenu -i -p "Replace $file in $destdir?")"
		fi
		[ "$replace" = "Yes" ] && cp "$file" "$destdir" && dunstify -t 2000 -i "$(readlink -f "$file")" "$file copied to $destdir" & ;;
	"m")
		[ -z "$destdir" ] && destdir="$(selectPath.sh "Move image(s) to:")"
		[ -z "$destdir" ] && exit
		replace="Yes"
		if [ -e "$destdir""$file" ]; then
			dunstify -i "$destdir""$file" "Old:"
			dunstify -i "$(readlink -f "$file")" "New:"
			replace="$(echo -e "No\nYes" | dmenu -i -p "Replace $file in $destdir?")"
		fi
		[ "$replace" = "Yes" ] && mv "$file" "$destdir" && dunstify -t 2000 -i "$destdir$file" "$file moved to $destdir" & ;;
	esac
done