-
-
Save kjoonlee/326b8f42e39bcc045e9932fef5511031 to your computer and use it in GitHub Desktop.
convert between NFC and NFD Unicode normalization (e.g. for Korean)
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
#!/usr/bin/env bash | |
die() { | |
echo "$*" 1>&2; exit 1; | |
} | |
print_usage() { | |
echo "usage: $my_name <FILE> | $my_name <DIRECTORY>" | |
} | |
my_name=$(basename "$0") | |
file_arg="$*" | |
if [ "$file_arg" = "" ]; | |
then | |
print_usage | |
exit 0 | |
fi | |
if [ "$my_name" = "nfc" ]; | |
then | |
convmv_args=(--nfc --notest -f utf8 -t utf8) | |
elif [ "$my_name" = "nfd" ]; | |
then | |
convmv_args=(--nfd --notest -f utf8 -t utf8) | |
else | |
die "error: please rename $0 into nfc or nfd." | |
fi | |
if [ -f "$file_arg" ]; | |
then | |
convmv "${convmv_args[@]}" "$file_arg" | |
elif [ -d "$file_arg" ]; | |
then | |
convmv -r "${convmv_args[@]}" "$file_arg" | |
else | |
print_usage | |
die "error: invalid argument!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment