aboutsummaryrefslogtreecommitdiffstats
path: root/.config/herbstluftwm/maim.sh
blob: 540e6fdd099b2e06ad2d429e96e638af5af9964d (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
#!/usr/bin/env zsh

local mpat='^(send|clipboard|normal)$'

local mode='normal'
local selection

local args
zparseopts -D -E -M -A args \
	m:	-mode=m \
	s	-selection=s

local optarg
for opt in ${(@k)args}; do
	unset optarg
	[[ -z $args[$opt] ]] || optarg=$args[$opt]
	case $opt in
		-m)
			[[ ! $(echo $optarg | grep -oE "$mpat") ]] \
				&& echo "err: bad mode" && exit
			mode=$optarg
			;;

		-s) selection=s ;;
	esac
done

[[ ${#@} -gt 0 ]] && echo "err: unrecognised arguments" && exit

local year
local stamp
date +%Y | read year
date +%s | read stamp

local fname="$HOME/images/scrot/$year/${year}-${stamp}.png"

mkdir -p $HOME/images/scrot/$year

if [[ $mode == clipboard ]]; then
	maim -u${selection} | xclip -selection clipboard -t image/png
	exit
fi

maim -u${selection} $fname && oxipng -o3 $fname

if [[ $mode == send ]]; then
	[[ -f $fname ]] \
		&& send $fname \
		&& notify-send "maim: sent ${fname:t} to /tmp/" \
		|| notify-send "maim: send to /tmp/ failed"
fi