summaryrefslogtreecommitdiff
path: root/scripts/define.sh
blob: 041f0a136751c7367ce32445ba568774b3022f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash

if [ -z "$1" ]; then
  echo "[!] Provide a word"
  exit 1
fi

RESP=$(curl -s -q https://api.dictionaryapi.dev/api/v2/entries/en/$1 | jq -r '
  [.[0].meanings[]
    | select(.partOfSpeech=="noun")
    | .definitions[].definition][0:2]
  | to_entries
  | map("\(.key + 1). \(.value)")
  | join("\n")
' 2>/dev/null)

if [ -z "$RESP" ]; then
  notify-send -t 10000 -u normal -i accessories-dictionary "Meaning Not Found!"
else
  notify-send -t 10000 -u normal -i accessories-dictionary "$1" "$RESP"
fi