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:
parent
4b4b4662ec
commit
6c27d23e19
1 changed files with 14 additions and 0 deletions
14
engine-q/cool_oneliners/dict.nu
Normal file
14
engine-q/cool_oneliners/dict.nu
Normal 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue