wayland-screenshot.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/zsh
  2. local resp="$(fuzzel --index -d <<'EOF'
  3. Whole screen
  4. Selected area
  5. Copy text with OCR (English)
  6. Copy text with OCR (Japanese)
  7. Select a color from the screen
  8. EOF
  9. )"
  10. local outfile="${HOME}/downloads/$(date +'screenshot-%F--%H-%M-%S.png')"
  11. # copy_with_ocr <language>
  12. function copy_with_ocr() {
  13. local area="$(slurp 2>&1)"
  14. if [[ "${area}" != 'selection cancelled' ]]; then
  15. local text="$(grim -g "${area}" -t png /dev/fd/1 |
  16. tesseract stdin stdout -l ${1})"
  17. wl-copy "${text}"
  18. notify-send -t 5000 "Coppied Text" "Coppied ${#text} characters"
  19. fi
  20. }
  21. case "${resp}" in
  22. 0)
  23. grim "${outfile}"
  24. ;;
  25. 1)
  26. local area="$(slurp 2>&1)"
  27. [[ "${area}" == 'selection cancelled' ]] ||
  28. grim -g "${area}" "${outfile}"
  29. ;;
  30. 2)
  31. copy_with_ocr eng
  32. ;;
  33. 3)
  34. copy_with_ocr jpn
  35. ;;
  36. 4)
  37. local color="$(hyprpicker -f hex -n -r)"
  38. (( ${#color} == 0 )) && exit
  39. wl-copy "${color}"
  40. notify-send -t 5000 "Color Selected" "${color}"
  41. ;;
  42. esac