Skip to content

Instantly share code, notes, and snippets.

@a-vasyliev
Last active July 11, 2023 08:58
Show Gist options
  • Save a-vasyliev/009cb30a7bd99a61d1bb to your computer and use it in GitHub Desktop.
Save a-vasyliev/009cb30a7bd99a61d1bb to your computer and use it in GitHub Desktop.
#!/bin/bash
# Перекодирует рекурсивно в текущем каталоге имена
# файлов и каталогов в транслит.
#
# Источник: http://www.ubuntu.sumy.ua/2011/03/translit.html
shopt -s nullglob
for NAME in * ; do
TRS=`echo $NAME | sed "y/абвгдезийклмнопрстуфхцы/abvgdezijklmnoprstufxcy/"`
TRS=`echo $TRS | sed "y/АБВГДЕЗИЙКЛМНОПРСТУФХЦЫ/ABVGDEZIJKLMNOPRSTUFXCY/"`
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//Ь/\'}
if [[ `file -b "$NAME"` == directory ]]; then
mv -v "$NAME" "$TRS"
cd "$TRS"
"$0"
cd ..
else
mv -v "$NAME" "$TRS"
fi
done
@bolshukhin
Copy link

Hello. And is it works with sub folders for translit?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment