#!/bin/sh
#
# Show noun synonyms and antonyms via Free Dictionary API.
#

[ -z "$1" ] && {
	printf "Usage: %s <word>\n" "$0"
	exit 1
}

word="$1"

curl -s "https://api.dictionaryapi.dev/api/v2/entries/en/$word" |
	jq -r '
  .[0].meanings[]
  | select(.partOfSpeech=="noun")
  | [
      "'$word'",
      "syn: " + ((.synonyms // []) | unique | join(",")),
      "ant: " + ((.antonyms // []) | unique | join(","))
    ]
  | join(" ")
' | tr -d '\r\n'
printf "\n"
