Add no color option (can be set as default variable).
parent
c3d275a714
commit
b26e703002
17
README.org
17
README.org
|
@ -23,6 +23,8 @@
|
||||||
|
|
||||||
To get help use flag ~-h~.
|
To get help use flag ~-h~.
|
||||||
|
|
||||||
|
~-f~ option (fuzzy matching) helps if no results were found.
|
||||||
|
|
||||||
* Dependencies
|
* Dependencies
|
||||||
|
|
||||||
This script uses following tools:
|
This script uses following tools:
|
||||||
|
@ -31,7 +33,7 @@
|
||||||
- recode
|
- recode
|
||||||
- sed
|
- sed
|
||||||
|
|
||||||
* Installation
|
* Installation
|
||||||
|
|
||||||
First you have to register at pons.com [[https://login.pons.com/login?return_to=https%253A%252F%252Fen.pons.com%252Fopen_dict%252Fpublic_api][api registration form]].
|
First you have to register at pons.com [[https://login.pons.com/login?return_to=https%253A%252F%252Fen.pons.com%252Fopen_dict%252Fpublic_api][api registration form]].
|
||||||
|
|
||||||
|
@ -44,8 +46,9 @@
|
||||||
~PONS_LANG~ to specify in which language is the word you are looking
|
~PONS_LANG~ to specify in which language is the word you are looking
|
||||||
translation for).
|
translation for).
|
||||||
|
|
||||||
Make your script executable and crate a symlink to it in your execution
|
Make your script executable and crate a symlink to it in your execution path.
|
||||||
path.
|
Simplier solution is to just a create ~alias~ in your ~.bashrc/.zshrc~ file
|
||||||
|
(~alias trans="<path-to-script>/trans.sh"~)
|
||||||
|
|
||||||
* How it works
|
* How it works
|
||||||
|
|
||||||
|
@ -62,3 +65,11 @@
|
||||||
|
|
||||||
I will rewrite this application in haskell once I found more time. Even before
|
I will rewrite this application in haskell once I found more time. Even before
|
||||||
that I'll implement some error handling.
|
that I'll implement some error handling.
|
||||||
|
|
||||||
|
** to do
|
||||||
|
- error handling
|
||||||
|
- rewrite into haskell
|
||||||
|
- ...
|
||||||
|
|
||||||
|
** done
|
||||||
|
- no color option
|
||||||
|
|
44
trans.sh
44
trans.sh
|
@ -54,7 +54,6 @@ pons_filter() {
|
||||||
# PONS_FILTER="$PONS_FILTER | select( .lang == \"$PONS_LANG\")"
|
# PONS_FILTER="$PONS_FILTER | select( .lang == \"$PONS_LANG\")"
|
||||||
# fi
|
# fi
|
||||||
if [ ! -z $PONS_RAW -a "$PONS_RAW" == "1" ] ; then
|
if [ ! -z $PONS_RAW -a "$PONS_RAW" == "1" ] ; then
|
||||||
# echo "Raw json output."
|
|
||||||
PONS_FILTER="[$PONS_FILTER ]"
|
PONS_FILTER="[$PONS_FILTER ]"
|
||||||
else
|
else
|
||||||
if [ $PONS_HITS -gt 0 ] ; then
|
if [ $PONS_HITS -gt 0 ] ; then
|
||||||
|
@ -63,17 +62,36 @@ pons_filter() {
|
||||||
PONS_FILTER="[$PONS_FILTER | {\"language_p\": .lang, \"hits_p\": [.hits[] | .roms | .[] | {\"headword_p\": .headword, \"wordclass_p\": .wordclass, \"arabs_p\": [ .arabs | .[] | {\"header_p\": .header, \"translations_p\": [.translations[] | {\"source_p\": .source, \"target_p\": .target }] } ] }] }]"
|
PONS_FILTER="[$PONS_FILTER | {\"language_p\": .lang, \"hits_p\": [.hits[] | .roms | .[] | {\"headword_p\": .headword, \"wordclass_p\": .wordclass, \"arabs_p\": [ .arabs | .[] | {\"header_p\": .header, \"translations_p\": [.translations[] | {\"source_p\": .source, \"target_p\": .target }] } ] }] }]"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#echo $PONS_FILTER
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pons_tags() {
|
pons_tags() {
|
||||||
source_t="$1"
|
source_t="$1"
|
||||||
#echo "$source_t\n"
|
|
||||||
source_t=$( recode html..latin1 <<< $source_t )
|
source_t=$( recode html..latin1 <<< $source_t )
|
||||||
old_color="$2"
|
old_color="$2"
|
||||||
spn_color="$3"
|
spn_color="$3"
|
||||||
source_t=$( sed -e "s/<span[^>]*>/$(tput setaf ${spn_color})/g" -e "s/<strong[^>]*>/$(tput bold)/g" -e "s/<acronym[^>]*>/$(tput dim)/g" -re "s/(<\/acronym>|<\/strong>|<\/span>)+/$(tput sgr0)$(tput setaf ${old_color})/g" <<< $source_t )
|
if [ -z $PONS_NOCOLOR ] ; then
|
||||||
printf " $(tput setaf ${old_color})%b$(tput sgr0)" "$source_t"
|
source_t=$( sed -e "s/<span[^>]*>/$(tput setaf ${spn_color})/g" -e "s/<strong[^>]*>/$(tput bold)/g" -e "s/<acronym[^>]*>/$(tput dim)/g" -re "s/(<\/acronym>|<\/strong>|<\/span>)+/$(tput sgr0)$(tput setaf ${old_color})/g" <<< $source_t )
|
||||||
|
printf " $(tput setaf ${old_color})%b$(tput sgr0)" "$source_t"
|
||||||
|
else
|
||||||
|
source_t=$( sed -e "s/<span[^>]*>//g" -e "s/<strong[^>]*>/$(tput bold)/g" -e "s/<acronym[^>]*>/$(tput dim)/g" -re "s/(<\/acronym>|<\/strong>|<\/span>)+/$(tput sgr0)/g" <<< $source_t )
|
||||||
|
printf " %b" "$source_t"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
pons_prettyfy_header() {
|
||||||
|
if [ -z $PONS_NOCOLOR ] ; then
|
||||||
|
hd=$(echo $hd | sed 's/<span.*>\(.*\)<\/span>/\\033\[0;34m\1\\033\[0;32m/g' | sed 's/<strong.*>\(.*\)<\/strong>/\\033\[1;32m\1\\033\[0;32m/g')
|
||||||
|
else
|
||||||
|
hd=$(echo -e $hd | sed 's/<span.*>\(.*\)<\/span>/\1/g' | sed 's/<strong.*>\(.*\)<\/strong>/\$\(tput bold\)\1\$\(tput sgr0\)/g')
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
pons_print_headword() {
|
||||||
|
if [ -z $PONS_NOCOLOR ] ; then
|
||||||
|
echo -e "\033[1;36m$hw\033[0m\t$cur_lang\t\033[0;34m$cw\033[0m"
|
||||||
|
else
|
||||||
|
echo -e "$(tput bold)$hw$(tput dim)\t$cur_lang\t$(tput sgr0)$cw"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 1. get language as variable and loop through it
|
# 1. get language as variable and loop through it
|
||||||
|
@ -94,11 +112,14 @@ pons_parse() {
|
||||||
sub_hit=$(jq -r ".hits_p | .[$hit_key]" <<< $sub_lang);
|
sub_hit=$(jq -r ".hits_p | .[$hit_key]" <<< $sub_lang);
|
||||||
hw=$(jq -r '"\(.headword_p)"' <<< $sub_hit ) #| sed -e 's/^"//' -e 's/"$//')
|
hw=$(jq -r '"\(.headword_p)"' <<< $sub_hit ) #| sed -e 's/^"//' -e 's/"$//')
|
||||||
cw=$(jq -r '"\(.wordclass_p)"' <<< $sub_hit)
|
cw=$(jq -r '"\(.wordclass_p)"' <<< $sub_hit)
|
||||||
echo -e "\033[1;36m$hw\033[0m\t$cur_lang\t\033[0;34m$cw\033[0m"
|
#echo -e "\033[1;36m$hw\033[0m\t$cur_lang\t\033[0;34m$cw\033[0m"
|
||||||
|
pons_print_headword
|
||||||
PONS_COUNT=$((PONS_COUNT + 1))
|
PONS_COUNT=$((PONS_COUNT + 1))
|
||||||
for ara_key in $(jq ".arabs_p | keys | .[]" <<< $sub_hit); do
|
for ara_key in $(jq ".arabs_p | keys | .[]" <<< $sub_hit); do
|
||||||
sub_ara=$(jq ".arabs_p | .[$ara_key]" <<< $sub_hit)
|
sub_ara=$(jq ".arabs_p | .[$ara_key]" <<< $sub_hit)
|
||||||
hd=$(jq -r " .header_p" <<< $sub_ara | sed 's/<span.*>\(.*\)<\/span>/\\033\[0;34m\1\\033\[0;32m/g' | sed 's/<strong.*>\(.*\)<\/strong>/\\033\[1;32m\1\\033\[0;32m/g')
|
# hd=$(jq -r " .header_p" <<< $sub_ara | sed 's/<span.*>\(.*\)<\/span>/\\033\[0;34m\1\\033\[0;32m/g' | sed 's/<strong.*>\(.*\)<\/strong>/\\033\[1;32m\1\\033\[0;32m/g')
|
||||||
|
hd=$(jq -r " .header_p" <<< $sub_ara )
|
||||||
|
pons_prettyfy_header
|
||||||
if [ ! -z "$hd" ] ; then
|
if [ ! -z "$hd" ] ; then
|
||||||
echo -e " $hd"
|
echo -e " $hd"
|
||||||
fi
|
fi
|
||||||
|
@ -174,6 +195,8 @@ pons_help () {
|
||||||
echo -e "\t-r :: Raw; Return raw result from pons."
|
echo -e "\t-r :: Raw; Return raw result from pons."
|
||||||
# echo -e "\t-t [type] :: Type; Return results in this type, txt by default (json, csv)." # long term plan
|
# echo -e "\t-t [type] :: Type; Return results in this type, txt by default (json, csv)." # long term plan
|
||||||
echo -e "\t-c :: Count; Count number of results."
|
echo -e "\t-c :: Count; Count number of results."
|
||||||
|
echo -e "\t-n [num]:: Limit number of results."
|
||||||
|
echo -e "\t-p :: Show plain text without colors (black&white)."
|
||||||
}
|
}
|
||||||
|
|
||||||
pons_options () {
|
pons_options () {
|
||||||
|
@ -188,7 +211,7 @@ pons_options () {
|
||||||
}
|
}
|
||||||
|
|
||||||
# FLAGS SETUP
|
# FLAGS SETUP
|
||||||
while getopts "fl:d:n:t:rhoec" option
|
while getopts "fl:d:n:t:rhoecp" option
|
||||||
do
|
do
|
||||||
case "${option}"
|
case "${option}"
|
||||||
in
|
in
|
||||||
|
@ -202,6 +225,7 @@ do
|
||||||
o) PONS_HELP=2;;
|
o) PONS_HELP=2;;
|
||||||
c) PONS_COUNT=1;;
|
c) PONS_COUNT=1;;
|
||||||
e) PONS_REF=1;;
|
e) PONS_REF=1;;
|
||||||
|
p) PONS_NOCOLOR=1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND -1))
|
shift $((OPTIND -1))
|
||||||
|
@ -209,8 +233,6 @@ PONS_WORD=$1
|
||||||
|
|
||||||
if [ "$PONS_HELP" == "1" ] ; then
|
if [ "$PONS_HELP" == "1" ] ; then
|
||||||
pons_help
|
pons_help
|
||||||
|
|
||||||
#return 0;
|
|
||||||
elif [ "$PONS_HELP" == "2" ] ; then
|
elif [ "$PONS_HELP" == "2" ] ; then
|
||||||
pons_options
|
pons_options
|
||||||
elif [ "$PONS_RAW" == "1" ] ; then
|
elif [ "$PONS_RAW" == "1" ] ; then
|
||||||
|
@ -224,8 +246,6 @@ else
|
||||||
pons_request
|
pons_request
|
||||||
pons_filter
|
pons_filter
|
||||||
PONS_JSON=$(echo $PONS_JSON | jq "$PONS_FILTER")
|
PONS_JSON=$(echo $PONS_JSON | jq "$PONS_FILTER")
|
||||||
#echo -e $PONS_JSON | jq .
|
|
||||||
# pons_parse
|
|
||||||
if [ "$PONS_HITS" -gt 0 ] ; then
|
if [ "$PONS_HITS" -gt 0 ] ; then
|
||||||
pons_parse_translate
|
pons_parse_translate
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue