-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwayshot.sh
executable file
·141 lines (125 loc) · 2.8 KB
/
wayshot.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
shopt -s extglob
if hash jq 2>/dev/null; then
JQ_AVAILABLE=1
fi
if hash wl-copy 2>/dev/null; then
WLCOPY_AVAILABLE=1
fi
USAGE="\
Usage: $(basename "$0") [options...] [filename]
Screenshots are written to specified filename or to a
timestamped file if not specified. See grim(1) for more info.
Use - as filename to write the screenshot to stdout.
Options:
-s Select a region to capture.
-w Select a window (only in sway).$([ -z "$JQ_AVAILABLE" ] && echo " (not available)")
-d <n> Delay by n seconds.
-c Save screenshot to clipboard.$([ -z "$WLCOPY_AVAILABLE" ] && echo " (not available)")
Will save to file too if a filename is specified.
-x Include cursors in the screenshot.
-h Show this help message.
"
function echo_usage {
echo ""
echo "$USAGE"
}
while (( $# > 0 )); do
case $1 in
-s)
REGION=yes
shift
;;
-w)
if [ -z "$JQ_AVAILABLE" ]; then
echo "jq was not found, please install jq to use this function."
exit 1
fi
SWAY_WINDOW=yes
shift
;;
-d)
shift
if [ -z "$1" ]; then
echo "-d requires a postive integer."
echo_usage
exit 1
elif ! [ "$1" -ge "$1" ] 2>/dev/null; then
echo "Not an integer: $1"
echo_usage
exit 1
elif [ "$1" -lt "1" ]; then
echo "Delay has to be a positive integer."
exit 1
fi
DELAY=$1
shift
;;
-c)
if [ -z "$WLCOPY_AVAILABLE" ]; then
echo "wl-copy was not found, please install wl-clipboard to use this function."
exit 1
fi
CLIPBOARD=yes
shift
;;
-x)
CURSOR=yes
shift
;;
-h)
echo "$USAGE"
exit 0
;;
-+(?))
echo "Unknown argument: $1"
echo_usage
exit 1
;;
*)
if [ -z "$FILENAME" ]; then
FILENAME="$1"
shift
else
echo "Too many arguments."
echo_usage
exit 1
fi
;;
esac
done
if [ -n "$REGION" ] && [ -n "$SWAY_WINDOW" ]; then
echo "You may only use one of -s and -w."
echo_usage
exit 1
fi
OPTS=()
if [ -n "$REGION" ]; then
OPTS+=("-g $(slurp)")
fi
if [ -n "$SWAY_WINDOW" ]; then
SELECTION=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp)
OPTS+=("-g $SELECTION")
fi
if [ -n "$CURSOR" ]; then
OPTS+=("-c")
fi
if [ -n "$DELAY" ]; then
for COUNT in $(seq "$DELAY" -1 1); do
echo -n "$COUNT "
sleep 1
done
echo "Smile! :)"
echo ""
fi
if [ -n "$CLIPBOARD" ]; then
if [ -n "$FILENAME" ]; then
grim "${OPTS[@]}" - | tee "$FILENAME" | wl-copy
else
grim "${OPTS[@]}" - | wl-copy
fi
elif [ -n "$FILENAME" ]; then
grim "${OPTS[@]}" "$FILENAME"
else
grim "${OPTS[@]}"
fi