Skip to content

Instantly share code, notes, and snippets.

@Frodox
Last active December 20, 2017 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frodox/b9fb3b1866fd27e36f2091ac5e99438b to your computer and use it in GitHub Desktop.
Save Frodox/b9fb3b1866fd27e36f2091ac5e99438b to your computer and use it in GitHub Desktop.
convert all *.m files cp-1251 to utf8
#!/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