Files
dotfiles/dot_config/nushell/nu_scripts/sourced/cool-oneliners/dict.nu
Cian Hughes 896af887ca Changed . token to _dot
This change allows the dotfiles to work with chezmoi (e.g: on windows)
and improves grepability with neovim/telescope
2024-11-07 13:52:17 +00:00

22 lines
671 B
Nu

# 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 join %20)
let link = ('https://api.dictionaryapi.dev/api/v2/entries/en/' + ($query|str replace ' ' '%20'))
let output = (http get $link | rename word)
let w = ($output.word | first)
if $w == "No Definitions Found" {
echo $output.word
} else {
echo $output
| get meanings
| flatten
| select partOfSpeech definitions
| flatten
| flatten
| reject "synonyms"
| reject "antonyms"
}
}