mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +00:00
Update dict.nu
Wrote --help, works without quotation marks
This commit is contained in:
parent
6ab6634764
commit
71b9df0ac3
1 changed files with 7 additions and 10 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue