Last active
December 27, 2015 10:59
-
-
Save nornagon/7314985 to your computer and use it in GitHub Desktop.
Become vocabulous with random word definitions on your shell.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Needs jq. brew install jq. | |
random_word_def() { | |
local random_word wordnik_for_word show_definition | |
random_word() { | |
perl -e 'rand($.) < 1 && ($line = $_) while <>; print $line' < /usr/share/dict/words | |
} | |
wordnik_for_word() { | |
curl -s http://api.wordnik.com/v4/word.json/"$1"/definitions'?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5' | |
} | |
show_definition() { | |
jq -r '{ "null":"?", "noun":"n", "verb-transitive":"t.v", "verb-intransitive":"i.v", | |
"preposition":"prep", "verb":"v", "adjective":"adj", | |
"phrasal-verb":"pv" } as $short | | |
.[] | | |
"\(.word), \($short[.partOfSpeech // "null"] // .partOfSpeech).: \(.text)"' | |
} | |
wordnik_for_word $(random_word) | show_definition | |
} | |
# if running interactively, | |
if [ "$PS1" ]; then | |
[ -f ~/.word_of_the_day ] && fold -s ~/.word_of_the_day | |
( random_word_def >| ~/.word_of_the_day & ) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment