Skip to content

Instantly share code, notes, and snippets.

@furushchev
Last active August 29, 2015 13:56
Show Gist options
  • Save furushchev/8973762 to your computer and use it in GitHub Desktop.
Save furushchev/8973762 to your computer and use it in GitHub Desktop.
function napr(){
local FROM TO
if [ $# -eq 1 ]; then
FROM="ru"; TO="ja"
elif [ $# -eq 3 ]; then
FROM=$2; TO=$3
else
echo -e "[usage] napr phrase [from(ru) to(ja)]\n To end press 'q'" 1>&2
echo -e "e.g\n napr например ru ja\n napr 例 ja ru" 1>&2
fi
if [ "$TO" != "" ]; then
echo "$1 ($FROM->$TO)"
curl -sSX GET "http://glosbe.com/gapi/tm?from=$FROM&dest=$TO&format=json&phrase=$1&pretty=true" | jq -r --arg FROM "$FROM" --arg TO "$TO" 'reduce .examples[] as $e ("";. + $FROM+":\t" + $e.first + "\n"+$TO+":\t" + $e.second + "\n\n")' 2>/dev/null | sed -e "s/$1/`echo -e '\033[33m'`$1`echo -e '\033\[m'`/g" | less -R
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment