#!/usr/bin/env bash

search_cache_path="${HOME}/.cache/rdict/searches"
mkdir -p "${search_cache_path}"

search_string=''
for i in $@;do
  if [[ -n "${search_string}" ]];then
    search_pad=" "
  fi
  search_string="${search_string}${search_pad}${i}"
done

search_encode="$(printf %s "${search_string}"|jq -sRr @uri)"
search_cache_file="${search_cache_path}/${search_encode}.json"
if [ ! -f "${search_cache_file}" ];then
  curl --silent --get "https://api.datamuse.com/words?ml=${search_encode}" | tee "${search_cache_file}" 1&>/dev/null
fi
jq '.[].word' "${search_cache_file}"
#jq -C '.[].word' "${search_cache_file}"

