Last active
October 5, 2023 23:08
-
-
Save Amooti73/9dac66ffee26f93baf211ab8c05949cd to your computer and use it in GitHub Desktop.
Click and drag to select a word on the screen and send it to rofi to display its definition with sdcv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Dependencies: tesseract-ocr imagemagick scrot xsel rofi | |
set -e | |
SCR_IMG=$(mktemp) | |
trap 'rm $SCR_IMG*' EXIT | |
scrot -s "$SCR_IMG.png" | |
mogrify -modulate 100,0 -resize 400% "$SCR_IMG.png" #should increase detection rate | |
tesseract "$SCR_IMG.png" "$SCR_IMG" &> /dev/null | |
cat "$SCR_IMG.txt" > wordy.txt | |
tr -d '\014' <wordy.txt > words.txt | |
src=$(cat words.txt) | |
test "$src" = "$(cat words.txt)" | |
rofi="rofi -dmenu -yoffset 30 -location 2" | |
pag() { \ | |
sed -e 1d \ | |
-e 's; _\([A-Z]\); \1;p' \ | |
-e '/^$/d' -e '/^-->/d' \ | |
| eval "$rofi" -l 20 -p 'Done' | |
} | |
phrase="$(echo $src | eval "$rofi" -markup -p 'Lookup: ')" | |
{ | |
sdcv -n --utf8-input --utf8-output "$phrase" | |
printf "Urban\n" | |
links -dump "https://www.urbandictionary.com/define.php?term=$phrase" \ | |
| sed -n '1,/Top def/d;/Get the mug/q;p' | |
} | pag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on dicx and this script from AskUbuntu.