mirror of https://git.sr.ht/~skiqqy/bin
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
840 B
54 lines
840 B
#!/usr/bin/env bash
|
|
# Get descriptions for words, basically a shitty curl+jq wrapper
|
|
# Please go support https://dictionaryapi.dev/
|
|
|
|
usage() {
|
|
cat << EOF
|
|
$ dict [options] WORDS...
|
|
|
|
Written by skiqqy
|
|
EOF
|
|
exit "${1:-0}"
|
|
}
|
|
|
|
# Fetch description(s) for a word
|
|
# Usage: fetch WORD
|
|
fetch()
|
|
{
|
|
word=${1:-word} # Todo, maybe add a word of the day if no arg given
|
|
|
|
printf '%s\n' "$word"
|
|
while read -r definition
|
|
do
|
|
printf "\n - %s\n" "${definition//\"/}"
|
|
done < <(curl -s "$api$word" | jq '.[].meanings[].definitions[].definition')
|
|
printf '\n'
|
|
}
|
|
|
|
main()
|
|
{
|
|
api='https://api.dictionaryapi.dev/api/v2/entries/en/'
|
|
|
|
while getopts h opt
|
|
do
|
|
case "$opt" in
|
|
h)
|
|
usage
|
|
;;
|
|
*)
|
|
usage 1
|
|
;;
|
|
esac
|
|
done
|
|
shift "$((OPTIND-1))"
|
|
|
|
[ -z "$1" ] && usage
|
|
|
|
while [ -n "$1" ]
|
|
do
|
|
fetch "$1" 2> /dev/null
|
|
shift 1
|
|
done
|
|
}
|
|
|
|
main "$@"
|
|
|