summaryrefslogtreecommitdiff
path: root/.local/bin/scst
blob: 51b00c13fd345737edb588b83f81d63ff6addcb7 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh

set -e

export NOTIFY_LONG=screenshot
export NOTIFY_SHORT="${0##*/}"

xnotify()
{
	notify 'Screenshot Copied' \
		'Screenshot successfully copied to the clipboard' \
		-i "$filename"
}

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

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

readonly outdir=${XDG_PICTURES_DIR:-$HOME/Pictures}/screen
readonly filebase=$(date +%F_%T.png)
readonly filename="$outdir/$filebase"
[ -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

opt="$(printf 'Copy screenshot\nEdit- and copy screenshot\n' | { osel || true; })"

case "$opt" in
'Copy screenshot')
	wl-copy <"$filename"
	xnotify
	;;
'Edit- and copy screenshot')
	swappy -f "$filename" -o - | pee wl-copy cat | sponge "$filename"
	xnotify
	;;
*)
	notify 'Screenshot Saved' \
		"The screenshot ‘$filebase’ was successfully saved" \
		-i "$filename"
esac