-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.sh
executable file
·60 lines (54 loc) · 1.42 KB
/
screenshot.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
#!/bin/bash
CMD=lqth
ARGS=""
PIPETO=ff2png
NOTIFY=
OUTFILE="$HOME/Pictures/screenshot.png"
SELTOOL=
COPY=
usage() {
echo "Usage: $0 [--region|--activewindow|--notify|--output <output_file>|--copy]" >&2
echo "The default output file: $OUTFILE" >&2
exit 1
}
while [ $# -gt 0 ]; do
arg="$1"
if [[ $1 == "-"* ]]; then
arg="${arg#-}"
else
echo "Invalid argument $1" >&2
exit 1
fi
case $arg in
o | output)
shift
if [[ $# -eq 0 ]]; then
echo "Missing file path" >&2
exit 1
fi
OUTFILE=$1
;;
r | region)
SELTOOL=xrectsel;;
w | activewindow)
ARGS="-w $(printf "%d" $(xdo id))" 2>/dev/null || ARGS="-w $(xdotool getactivewindow)";;
n | notify)
NOTIFY="notify-send --urgency=low --expire-time=900 --app-name=$0";;
c | copy)
COPY="xclip -selection clipboard -t image/png -i";;
*)
usage;;
esac
shift
done
if [[ -n $SELTOOL ]]; then
[[ -n $NOTIFY ]] && $NOTIFY "Select an region to take a screenshot for"
ARGS="-r $($SELTOOL "x:%x,y:%y,w:%w,h:%h")"
fi
if [[ -n $COPY ]]; then
$CMD $ARGS | $PIPETO | $COPY
[[ -n $NOTIFY ]] && $NOTIFY "Screenshot copyed to system clipbooard"
else
$CMD $ARGS | $PIPETO > $OUTFILE
[[ -n $NOTIFY ]] && $NOTIFY "Screenshot saved at: $OUTFILE"
fi