~yerinalexey/dotfiles

ref: 144a38b0aa0a39003633d53b77fe4e3ca29c054b dotfiles/scripts/sht -rwxr-xr-x 1.0 KiB
144a38b0Alexey Yerin river,update-volume: fix old wob crashes 6 months ago
                                                                                
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 -e

SCREENSHOT_PATH=/tmp/screen.png

region=""

pick_color() {
	color=$(
		grim -g "$(slurp -p)" -t ppm - | \
			convert - -format "%[pixel:p{0,0}]" txt:- | \
			tail -1 | \
			grep "#" | \
			awk '{print $3}'
	)
	[ -z "$color" ] && exit

	wl-copy "$color"

	# Generate preview image to include in the notification
	preview="$(mktemp /tmp/color-preview-XXXX.png)"
	convert -size 50x50 xc:"$color" "$preview"

	notify-send -t 5000 "Screenshot" "$color copied!" --icon="$preview"

	rm "$preview"
}

case "$1" in
	window)
		# Simple magic to snap selection to windows
		region="$(swaymsg -t get_tree | \
			jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | \
			slurp)"
		;;
	area)
		region="$(slurp)"
		;;
	full) ;;
	color)
		pick_color
		exit
		;;
	*)
		printf 'Usage: sht <window|area|full|color>\n'
		exit 1
		;;
esac

# If region is empty, don't pass it to grim
if [ -n "$region" ]; then
	grim -g "$region" "$SCREENSHOT_PATH"
else
	grim "$SCREENSHOT_PATH"
fi

notify-send "Screenshot" "Screenshot has been taken"