You are not logged in.
Rationale
This script aims to help improve the user's english vocabulary and undestarting.
Dependencies: grep(GNU), curl, bash
Git
https://github.com/argent0/smallTools/b … my-dict.sh
Code
#!/bin/bash
# Basic dictionary
#
# Features:
# * Severe input coercion.
# * Cache system.
# * Case insensitive.
# * Colorized output
# * Try not to store useless data
if (( $# != 1 ))
then
echo "Please consider providing a word(one) to search."
exit 1
fi
if grep -qe '[^[:alpha:]]' <<< "$1" #severe input coercion
then
echo "Please express your word using letters only."
exit 1
fi
# only reach here if the input is a word
if [[ -v XDG_CACHE_HOME ]]
then
cache_dir="$XDG_CACHE_HOME/my-dict"
else
cache_dir="$HOME/.my-dict" #you asked for it
fi
mkdir --parents "$cache_dir" #no errors
word=$(tr "A-Z" "a-z" <<< "$1") #case insensitive
data_base_entry="$cache_dir/$word"
if [[ ! -a $data_base_entry ]] #if database entry doesn't exist
then #be carefull
#create the file first in case we fail at curl
if ! touch $data_base_entry
then
echo "Can't touch file: \"$data_base_entry\"."
exit 1
fi
if ! curl "dict://dict.org/d:$word:*" >> "$data_base_entry"
then # curl failed
rm "$data_base_entry" #no errors, because it should exist by now
echo "Failed to retrieve definition from dict.org."
exit 1
fi
#what if we didn't find anything?
if grep -q "552 no match" "$data_base_entry" # Try not to store useless data
then
rm "$data_base_entry" #no errors, because it should exist by now
echo "No match found. \"$word\""
exit 1
fi
fi
#anyway
# Riviera's trick ( presented by dualbus )
grep -i --color -e "$word" -e "^" "$data_base_entry"
Cheers
.--.-.... --. .-.-.-..-.-..--....- .- .-...-... --..-..-... -.-.----. ..-.. ...------....-...-.-----..-- .-....---.-..- --. .-.-.-..-.-.--- .-...-... --..-..-... -.-.----. .-...- -......-...-...-..-..-
Offline
Thanks for making this! It seems to work really well and I already made an alias for it to use it easier. I'm pretty sure this comes really useful in many cases (at least for me) because sometimes I might have some naughty difficulties in some situations.
Offline
This dictionary is wonderful. The convenience of a commandline tool without having to (manually) search a website. Also, I love how this also pulls up synonyms, which has me discovering even more interesting words. Many thanks.
Registed Linux User 483618
Offline