xxwhirlpool
·
2026-05-21
1#!/usr/bin/env bash
2#
3# https://github.com/aryuuu/dmenu-dict/blob/main/dmenu-dict
4#
5# https://github.com/BreadOnPenguins/scripts/blob/master/define_word
6
7dict() {
8 word=$(echo " " | dmenu -i -c -l 10 -p "dictionary!")
9
10 if [[ -n "$word" ]]; then
11 response=$(curl -s --connect-timeout 5 --max-time 10 "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word")
12 notif=$(echo "$response" | jq -r '[.[].meanings[] | {pos: .partOfSpeech, def: .definitions[].definition}] | .[:3].[] | "\n\(.pos). \(.def)"')
13 notify-send -t 30000 "$word" "$notif"
14 fi
15}
16
17synonyms() {
18 word=$(echo " " | dmenu -i -c -l 10 -p "get synonyms")
19
20 if [[ -n "$word" ]]; then
21 response=$(curl -s --connect-timeout 5 --max-time 10 "https://api.dictionaryapi.dev/api/v2/entries/en_US/$word")
22 notif=$(echo "$response" | jq -r '.[].meanings[].synonyms.[]')
23
24 if [[ "$notif" -eq 0 ]]; then
25 notify-send -t 30000 "$word" "no synonyms found"
26 else
27 notify-send -t 30000 "$word" "$notif"
28 fi
29 fi
30}
31
32menu() {
33 cmd=$(printf "dictionary\\nsynonyms" | dmenu -i -c -l 10 -p "words!")
34 case "$cmd" in
35 dictionary) dict;;
36 synonyms) synonyms;;
37 esac
38}
39
40menu