]> git.phdru.name Git - dotfiles.git/blob - bin/unicode_norm_nfd.py
Feat(recode-filenames-recursive): Allow to omit parameters
[dotfiles.git] / bin / unicode_norm_nfd.py
1 #! /usr/bin/env python3
2 # https://stackoverflow.com/a/518232/7976758
3
4 import sys
5 import unicodedata
6
7
8 def strip_accents(s):
9     return ''.join(c for c in unicodedata.normalize('NFD', s)
10                    if unicodedata.category(c) != 'Mn')
11
12
13 def latin1_to_ascii(uinput):
14     if isinstance(uinput, bytes):
15         uinput = uinput.decode(sys.getfilesystemencoding())
16     return strip_accents(uinput)
17
18
19 if __name__ == '__main__':
20     if len(sys.argv) == 1:
21         sys.exit('Usage: %s name\n' % sys.argv[0])
22     for name in sys.argv[1:]:
23         print(latin1_to_ascii(name))