#!/bin/sh

blue=$(tput setaf 4)
red=$(tput setaf 1)
yellow=$(tput setaf 3)
bold=$(tput bold)
underline=$(tput smul)
esc=$(tput sgr0)

if [ -z "$1" ]; then
  fzf --prompt "Find word: " --no-multi < /usr/share/dict/american-english | xargs -t -r dict
else
  curl -s "dict://dict.org/d:$1" | sed -n -e '/^151.*/,/^\./p' | sed -e 's/^151.*//g' -e '/^\./D' -e '/^\s*1\./i\\' -e "s/{\([^{]*\)}/${esc}${underline}${yellow}\1${esc}/g" -e "s/^\($1\)\(\W\)/${esc}${bold}${red}\1${esc}\2/gI" -e "s/^\(\s*\)\([0-9]\.\)/\1${esc}${bold}${blue}\2${esc}/g" -e 's/--/—/g' -e 's/—\(\w\)/— \1/g'
fi
