├── LICENSE ├── README.md ├── word-lookup.gif └── word-lookup.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Alexander G. Nielsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # word-lookup 📚 2 | 3 | ![](https://github.com/4lgn/word-lookup/raw/master/word-lookup.gif) 4 | 5 | ## Requirements 6 | 7 | - [xclip](https://github.com/astrand/xclip) (only for X11) 8 | - [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (only for wayland) 9 | - [dunst](https://github.com/dunst-project/dunst) 10 | 11 | ## License 12 | 13 | Copyright (c) 2021 Alexander G. Nielsen. See [LICENSE](https://github.com/4lgn/word-lookup/blob/master/LICENSE) for details. 14 | -------------------------------------------------------------------------------- /word-lookup.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4lgn/word-lookup/5b0537cd5d39cbd0aead8edcbb0486178e110072/word-lookup.gif -------------------------------------------------------------------------------- /word-lookup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | usage(){ 4 | echo "Usage: $(basename "$0") [-h] 5 | Looks up the definition of currently selected word. 6 | -w: Use the wayland clipboard (instead of X11) " 7 | 8 | } 9 | 10 | USEWAYLAND=false 11 | 12 | while getopts 'hw' c 13 | do 14 | case $c in 15 | h) usage; exit ;; 16 | w) USEWAYLAND=true ;; 17 | *) usage; exit 1 ;; 18 | esac 19 | done 20 | 21 | shift $((OPTIND-1)) 22 | 23 | if [ $USEWAYLAND = true ] 24 | then 25 | word=$(wl-paste -p) 26 | else 27 | word=$(xclip -o) 28 | fi 29 | 30 | res=$(curl -s "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word") 31 | regex=$'"definition":"\K(.*?)(?=")' 32 | definitions=$(echo "$res" | grep -Po "$regex") 33 | separatedDefinition=$(sed ':a;N;$!ba;s/\n/\n\n/g' <<< "$definitions") 34 | notify-send -a "word-lookup" "$word" "$separatedDefinition" 35 | --------------------------------------------------------------------------------