Created
May 22, 2018 21:38
-
-
Save chlp/d7f3cb588e9b404886b0382adfd20bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
translit() { | |
local NAME=${*:-$(cat)}; | |
local TRS; | |
TRS=$(sed "y/абвгдезийклмнопрстуфхцы/abvgdezijklmnoprstufxcy/" <<< "$NAME") | |
TRS=$(sed "y/АБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/ABVGDEZIJKLMNOPRSTUFXCY/" <<< "$TRS") | |
TRS=${TRS//ч/ch}; | |
TRS=${TRS//Ч/CH} TRS=${TRS//ш/sh}; | |
TRS=${TRS//Ш/SH} TRS=${TRS//ё/jo}; | |
TRS=${TRS//Ё/JO} TRS=${TRS//ж/zh}; | |
TRS=${TRS//Ж/ZH} TRS=${TRS//щ/sh\'}; | |
TRS=${TRS///SH\'} TRS=${TRS//э/je}; | |
TRS=${TRS//Э/JE} TRS=${TRS//ю/ju}; | |
TRS=${TRS//Ю/JU} TRS=${TRS//я/ja}; | |
TRS=${TRS//Я/JA} TRS=${TRS//ъ/\`}; | |
TRS=${TRS//ъ\`} TRS=${TRS//ь/\'}; | |
TRS=${TRS//Ь/\'} | |
hash iconv &> /dev/null && TRS=$(iconv -c -f UTF8 -t ASCII//TRANSLIT <<< "$TRS") | |
echo "$TRS"; | |
} | |
dir="/Volumes/NO NAME" | |
if [[ $1 ]]; then | |
dir=$1 | |
fi | |
cd "$dir" | |
echo `pwd` | |
echo 'Continue? y?' | |
read continue | |
if [ ! "$continue" = 'y' ]; then | |
echo 'exit' | |
exit | |
fi | |
echo 'continue' | |
translit_move() { | |
for NAME in * ; do | |
if [ ! "$NAME" = '*' ]; then | |
TRS=`translit <<< $NAME` | |
if [[ `file -b "$NAME"` == directory ]]; then | |
if [ ! "$NAME" = "$TRS" ]; then | |
mv -v "$NAME" "$TRS" | |
fi | |
cd "$TRS" | |
translit_move | |
cd .. | |
fi | |
if [ -f "$NAME" ]; then | |
mv -v "$NAME" "$TRS" | |
fi | |
fi | |
done | |
} | |
translit_move |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment