~jbauer/dotfiles

ref: daebf07b03e1fe9fe376eb75d5dd061c8fa047d3 dotfiles/.local/bin/screenshot -rwxr-xr-x 1.3 KiB
daebf07bJake Bauer Update README 11 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
#!/bin/sh
# Simple POSIX shell script to take a screenshot using dmenu prompts

# Get active monitors and format the geometry string in a way that maim can understand
monitors=$(xrandr --listactivemonitors | grep + | awk '{print $4, $3}' | awk -F'[x/+* ]' '{print $1,$2"x"$4"+"$6"+"$7}')

targets="Fullscreen
Current Window
Selected Region
$(echo "$monitors" | awk '{print $1}')"

destinations="File
Clipboard
Both"

flags="-u"

target=$(echo "$targets" | dmenu -i -l 20 -p 'Take screenshot of:' "$@") || exit 1
saveto=$(echo "$destinations" | dmenu -i -l 20 -p 'Save to:' "$@" ) || exit 1

filename="$HOME/media/pics/$(date +"%Y-%m-%d_%H-%M-%S").png"

case "$target" in
	"Fullscreen")
	;;
	"Current Window")
		flags="$flags -i $(xdotool getactivewindow)"
	;;
	"Selected Region")
		flags="$flags -s"
	;;
	*)
		geometry=$(echo "$target" | awk '{print $2}')
		flags="$flags -g $geometry"
	;;
esac

case "$saveto" in
	"File")
		maim $flags > "$filename" \
		&& notify-send "Screenshot Captured" "Saved to $filename"
	;;
	"Clipboard")
		maim $flags | xclip -sel c -t image/png \
		&& notify-send "Screenshot Captured" "Copied to clipboard"
	;;
	"Both")
		maim $flags | tee "$filename" | xclip -sel c -t image/png \
		&& notify-send "Screenshot Captured" "Saved to $filename and copied to clipboard"
	;;
	*)
		exit 1
	;;
esac