add script to use dict.cc in CLI without having to use elinks or another browser

This commit is contained in:
David Daily 2020-02-17 03:22:58 -06:00
parent a561e06bf9
commit fe79ee7882
1 changed files with 30 additions and 0 deletions

30
dictcc.sh Executable file
View File

@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~