84 lines
2.4 KiB
Bash
Executable File
84 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
set -ef
|
|
|
|
OUTFILE="$HOME/pics/screenshots/$(date +"%Y-%m-%d_%H-%M-%S").jxl" # output file template, change as needed
|
|
MENU="fzfmenu"
|
|
CATBOX_USERHASH="" # catbox userhash
|
|
BASEIFS=$IFS
|
|
|
|
clean() {
|
|
[ -n "$nsxiv_pid" ] && kill "$nsxiv_pid"
|
|
[ -f "$tmpfreeze" ] && rm -f "$tmpfreeze"
|
|
rm -f "$tmpfp"
|
|
}
|
|
|
|
save() {
|
|
cjxl "$tmpfp" -d 0.0 "$OUTFILE" && notify-send -u low "$OUTFILE"
|
|
exit 0
|
|
}
|
|
|
|
savemenu() { printf 'save?' | $MENU && save; }
|
|
|
|
choose() {
|
|
while true; do
|
|
case "$(printf "save\nedit\nscan\nupload" | $MENU -p "screenshot actions")" in
|
|
save) save ;;
|
|
edit)
|
|
h1="$(md5sum "$tmpfp")"
|
|
gimp -n "$tmpfp"
|
|
h2="$(md5sum "$tmpfp")"
|
|
[ -n "$h1" != "$h2" ] && save # changed, save
|
|
;;
|
|
scan)
|
|
zdata="$(zbarimg -1 "$tmpfp")" || zdata="error: scan failed with exit code $?"
|
|
export zdata
|
|
urxvt -g 75x25 -e sh -c 'printf "%s\n" "${zdata#*:}" | vim -' &
|
|
printf '%s\n' "${zdata#*:}"
|
|
;;
|
|
upload)
|
|
set +e
|
|
ut="$(printf "owo\ncatbox\nlitterbox (1h)\nlitterbox (12h)\nlitterbox (24h)\nlitterbox (72h)" | $MENU -p "upload")"
|
|
case $ut in
|
|
owo) owo -u "$tmpfp" | xclip -sel clipboard ;;
|
|
catbox) curl -F "reqtype=fileupload" ${CATBOX_USERHASH:+-F "userhash=$CATBOX_USERHASH"} -F "fileToUpload=@$tmpfp" https://catbox.moe/user/api.php | xclip -sel clipboard ;;
|
|
litterbox*) IFS=" ()"; set -- $ut ; curl -F "reqtype=fileupload" -F "time=$2" -F "fileToUpload=@$tmpfp" https://litterbox.catbox.moe/resources/internals/api.php | xclip -sel clipboard ;;
|
|
*) continue ;;
|
|
esac
|
|
[ "$?" -eq 0 ] && notify-send "uploaded and copied successfully!" || notify-send "upload error! you should probably save the image"
|
|
set -e
|
|
;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
ss() {
|
|
[ "$ssopts" = "-g" ] && ssopts="$(hacksaw -f "-i %i -g %g")"
|
|
shotgun $ssopts "$tmpfp"
|
|
[ -n "$nsxiv_pid" ] && kill "$nsxiv_pid" && nsxiv_pid="" # unfreeze
|
|
xclip -selection clipboard -t image/png < "$tmpfp" # copy screenshot
|
|
choose
|
|
}
|
|
|
|
freeze() {
|
|
tmpfreeze="$(mktemp -t screenshot_freeze_XXXX.png)"
|
|
shotgun "$tmpfreeze"
|
|
nsxiv -b -N SCREENSHOT_FREEZE "$tmpfreeze" &
|
|
nsxiv_pid=$!
|
|
# window manager makes it fullscreen (yippee!)
|
|
}
|
|
|
|
tmpfp="$(mktemp -t screenshot_XXXX.png)"
|
|
trap 'clean' INT HUP EXIT
|
|
|
|
while getopts :srwf OPT; do
|
|
case "$OPT" in
|
|
s) ssopts="-s" ;; # screen
|
|
r) ssopts="-g" ;; # region
|
|
w) ssopts="-i $(xdotool getactivewindow)" ;; # active window
|
|
f) freeze ;; # freeze screen, only useful with -r
|
|
*) echo "invalid option: -$OPTARG" && exit 1 ;;
|
|
esac
|
|
done
|
|
ss
|