Skip to content

Instantly share code, notes, and snippets.

@kjoonlee
Last active July 31, 2022 10:18
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 kjoonlee/326b8f42e39bcc045e9932fef5511031 to your computer and use it in GitHub Desktop.
Save kjoonlee/326b8f42e39bcc045e9932fef5511031 to your computer and use it in GitHub Desktop.
convert between NFC and NFD Unicode normalization (e.g. for Korean)
#!/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