-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot
executable file
·68 lines (59 loc) · 1.67 KB
/
screenshot
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# prompt the user to select a screenshot type then do that screenshot
notify_interactive_mode () {
notify-send "Screenshot 💻" "Screenshotting in \"${1}\" mode" --expire-time=1000
}
notify_selection_cancelled () {
notify-send "Screenshot 🙅♀️" "Selection cancelled" --expire-time=2500
}
screenshot_options=(
"screen"
"screen-with-cursor"
"window"
"selection"
)
screenshot_type=$(\
echo ${screenshot_options[*]} \
| tr "[:space:]" '\n' \
| floating-fzf
)
if [ $? -ne 0 ]; then
notify-send "Screenshot 🤷♂️" "No screenshot mode chosen" --expire-time=2500
exit 1
fi
case "$screenshot_type" in
"screen")
grim
;;
"screen-with-cursor")
grim -c
;;
"selection")
notify_interactive_mode "selection"
selection_rectangle=$(slurp)
if [ $? -ne 0 ]; then
notify_selection_cancelled
exit 1
fi
grim -g "${selection_rectangle}"
;;
"window")
notify_interactive_mode "window"
# Use slurp to get the borders of a window
window_borders=$(\
swaymsg -t get_tree \
| jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' \
| slurp
)
if [ $? -ne 0 ]; then
notify_selection_cancelled
exit 1
fi
grim -g "${window_borders}"
;;
*)
notify-send "Screenshot 🤷♂️" "Unrecognized mode: ${screenshot_type}" --expire-time=2500
exit 1
;;
esac
notify-send --expire-time=2500 "Screenshot 👍" "Screenshot captured!" --category=screenshot