31 lines
692 B
Bash
31 lines
692 B
Bash
|
#!/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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|