diff --git a/cool_oneliners/dict.nu b/cool_oneliners/dict.nu index d890e84..3678ffd 100644 --- a/cool_oneliners/dict.nu +++ b/cool_oneliners/dict.nu @@ -1,16 +1,13 @@ -#As the name suggests, the function returns you the definition and example of the sought English word -#(or breaks if it can't find the word because the API uses different columns for successful and invalid searches) - -#usage: dict word -#usage: dict "word with space" - -def dict [word: string] { - let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($word|str find-replace ' ' '%20')) +# 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) + let w = ($output.word | first) - if $w == "No Definitions Found" {echo $output.word} {echo $output | + if $w == "No Definitions Found" {echo $output.word} {echo $output | get meanings.definitions | select definition example }