1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

port dict.nu over to engine-q/cool_oneliners

This commit is contained in:
Michael Angerman 2022-02-09 21:28:21 -08:00
parent 4b4b4662ec
commit 6c27d23e19

View file

@ -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
}
}