From fe79ee7882616338b2665d63ecf5a6da362def53 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 17 Feb 2020 03:22:58 -0600 Subject: [PATCH] add script to use dict.cc in CLI without having to use elinks or another browser --- dictcc.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 dictcc.sh diff --git a/dictcc.sh b/dictcc.sh new file mode 100755 index 0000000..15e6d1d --- /dev/null +++ b/dictcc.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# dictcc.sh - simple cli interface to dict.cc +# Usage: dictcc.sh TERM [LANG1] [LANG2] [NUM] defaults to de->en with 10 results +if [ -z "$2" ]; then + lf=de +else + lf=$2 +fi + +if [ -z "$3" ]; then + lt=en +else + lt=$3 +fi + + +if [ -n "$4" ]; then + num=$4 +else + num=10 +fi + +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +curl -s -X GET -G "https://$lf$lt.dict.cc/" --data-urlencode "s=$1" | \ + grep -E "(c1Arr|c2Arr)" | \ + sed -e "s/var \(c1Arr\|c2Arr\) = new Array(\"\",//" -e "s/);//" \ + -e "s/\"//g" | awk 'NR == 1{split($0,lang1,",");} NR == 2{split($0,lang2,",");} + END{for(i in lang1) print lang1[i] , "\t" , lang2[i]}' | head -n $num +echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~