Skip to content

Instantly share code, notes, and snippets.

@fami-com
Last active May 17, 2016 18:09
Show Gist options
  • Save fami-com/d02e5cde7df177a5dffc584c5b6d7dfc to your computer and use it in GitHub Desktop.
Save fami-com/d02e5cde7df177a5dffc584c5b6d7dfc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# enkoi - encode a text from cp1251 to koi8-r
# options: -e switch to encode mode
# -d switch to decode mode
# licensed under the terms of MIT license
#
version="0.1"
function helpexit ()
{
printf "Usage: %s [-e|-d] [OPTION]...\n" $(basename $0)
exit 1
} >&2
if [ "$#" -lt 1 ]
then
helpexit
fi
tmp="$1"
if [[ $1 = '-e' ]] || [[ $1 = '-d' ]]
then
shift
fi
for i in "$@"
do
case "$tmp" in
"-d" )
echo $i | tr '\n' ' ' | iconv -t koi8-r | iconv -f cp1251
;;
"-e" )
echo $i | tr '\n' ' ' | iconv -t cp1251 | iconv -f koi8-r
;;
* )
helpexit
;;
esac
done
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment