summaryrefslogtreecommitdiff
path: root/.local/bin/scst
blob: 6b63009cfa35847cad9d0db1bcbd0d9906039caf (plain) (blame)
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
#!/bin/sh

set -e

notify() {
	notify-send -a ${0##*/} -i "$filename" 'Screenshot copied' \
		'Screenshot successfully copied to the clipboard'
}

if [ $# -eq 1 -a "$1" = "-f" ]; then
	fflag=true
	shift
fi

[ $# -ge 1 ] && {
	echo "Usage: ${0##*/} [-f]" >&2
	exit 1
}

outdir=${XDG_PICTURES_DIR:-$HOME/Pictures}/screen
filename="$outdir/`date +%F_%T.png`"
[ -d "$outdir" ] || mkdir -p "$outdir"

if ${fflag:-false}; then
	grim "$filename"
else
	slurp 2>/dev/null | ifne grim -g - "$filename"
fi

[ -f "$filename" ] || exit 1

printf 'Copy screenshot\nEdit- and copy screenshot\n' \
	| osel \
	| if read res && [ "$res" = 'Copy screenshot' ]; then
		wl-copy <"$filename"
		notify
	elif [ "$res" = 'Edit- and copy screenshot' ]; then
		swappy -f "$filename" -o - | pee wl-copy cat | sponge "$filename"
		notify
	fi