#! /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 DP-1 $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