From 6c27d23e1987eedd9f773d559dd87e730773b188 Mon Sep 17 00:00:00 2001 From: Michael Angerman <1809991+stormasm@users.noreply.github.com> Date: Wed, 9 Feb 2022 21:28:21 -0800 Subject: [PATCH] port dict.nu over to engine-q/cool_oneliners --- engine-q/cool_oneliners/dict.nu | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 engine-q/cool_oneliners/dict.nu diff --git a/engine-q/cool_oneliners/dict.nu b/engine-q/cool_oneliners/dict.nu new file mode 100644 index 0000000..5f5aa30 --- /dev/null +++ b/engine-q/cool_oneliners/dict.nu @@ -0,0 +1,14 @@ +# Function querying free online English dictionary API for definition of given word(s) +def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs" +] { + let query = ($word | str collect %20) + let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str find-replace ' ' '%20')) + let output = (fetch $link | + rename word) + let w = ($output.word | first) + + if $w == "No Definitions Found" {echo $output.word} else {echo $output | + get meanings.definitions | + select definition example + } +}