Last active
December 20, 2017 18:44
-
-
Save Frodox/b9fb3b1866fd27e36f2091ac5e99438b to your computer and use it in GitHub Desktop.
convert all *.m files cp-1251 to utf8
This file contains hidden or 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 | |
set -u -o pipefail | |
if [[ -z "${1-}" ]]; then | |
echo "$0 <dir>" >&2 | |
exit 1 | |
else | |
DIR=$(readlink -f "$1") | |
fi | |
if [[ ! -d "$DIR/backup" ]]; then | |
echo "Backing up..." | |
rsync -vr . "$DIR/backup" | |
else | |
read -r -s -p "Run twice in same dir. Are you sure? (Ctrl+C to cancel) " key | |
fi | |
find "$DIR" -type f -name "*.m" | while read line; do | |
echo "Precessing $old_path ..." | |
old_path=$line | |
new_path=$line-new | |
iconv -f WINDOWS-1251 -t utf8 "$old_path" -o "$new_path" | |
mv "$new_path" "$old_path" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment