blob: bf1af9699193bfaf0f8959d26158abff34246bcd (
plain)
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
|
#! /usr/bin/env bash
if [[ $1 == "qrcode" || $1 == "color" ]]; then
mime_type="text/plain"
else
dir="$HOME/pics/screenshots/`date +'%m-%Y'`"
if [ ! -d $dir ]; then mkdir -p $dir; fi
while : ; do
filename="screenshot-`date +'%m-%d-%y'`-`hexdump -n 3 -e '1/4 "%02X"' /dev/random`"
[ -e $dir/$filename.* ] || break
done
if [[ $1 == "video" ]]; then
output="$dir/$filename"".mkv"
mime_type="video/x-matroska"
else
output="$dir/$filename"".png"
mime_type="image/png"
fi
fi
parseqr () { zbarimg -q1 - | cut -d ':' -f 2-; }
parsecolor () { magick - -format '%[pixel:p{0,0}]' txt:- | awk 'END {printf $3}'; }
if [[ $XDG_SESSION_TYPE == "wayland" ]]; then
copy="wl-copy -t $mime_type"
case $1 in
"qrcode") grim -t png -g "$(slurp)" - | parseqr | $copy ;;
"color") grim -t ppm -g "$(slurp -p)" - | parsecolor | $copy ;;
"video") wf-recorder -a -g "$(slurp)" -f $output ;;
"main") grim -t png -o $MAIN_MONITOR $output ;;
"full") grim -t png $output ;;
"output") grim -t png -g "$(slurp -o)" $output ;;
*) grim -t png -g "$(slurp)" $output ;;
esac
else
copy="xclip -selection clipboard -target $mime_type -i"
case $1 in
"full") import -window root $output ;;
*)
area=$(slop -f "%g") || exit 1
read -r G < <(echo $area)
import -window root -crop $G $output ;;
esac
fi
if [[ $1 != "qrcode" && $1 != "color" && $1 != "video" && -f $output ]]; then
cat $output | $copy;
fi
|