random-scripts/wayland-screenshot.sh

47 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/zsh
local resp="$(fuzzel --index -d <<'EOF'
Whole screen
Selected area
Copy text with OCR (English)
Copy text with OCR (Japanese)
Select a color from the screen
EOF
)"
local outfile="${HOME}/downloads/$(date +'screenshot-%F--%H-%M-%S.png')"
# copy_with_ocr <language>
function copy_with_ocr() {
local area="$(slurp 2>&1)"
if [[ "${area}" != 'selection cancelled' ]]; then
local text="$(grim -g "${area}" -t png /dev/fd/1 |
tesseract stdin stdout -l ${1})"
wl-copy "${text}"
notify-send -t 5000 "Coppied Text" "Coppied ${#text} characters"
fi
}
case "${resp}" in
0)
grim "${outfile}"
;;
1)
local area="$(slurp 2>&1)"
[[ "${area}" == 'selection cancelled' ]] ||
grim -g "${area}" "${outfile}"
;;
2)
copy_with_ocr eng
;;
3)
copy_with_ocr jpn
;;
4)
local color="$(hyprpicker -f hex -n -r)"
(( ${#color} == 0 )) && exit
wl-copy "${color}"
notify-send -t 5000 "Color Selected" "${color}"
;;
esac