]>
git.wh0rd.org - home.git/blob - .bin/aspell-sort-pws
3 """Update & sort personal dictionaries."""
12 """Return a CLI parser."""
13 parser
= argparse
.ArgumentParser(description
=__doc__
)
14 parser
.add_argument('words', nargs
='*',
15 help='words to add to the dictionary')
20 opts
= parser
.parse_args(argv
)
22 locale
.setlocale(locale
.LC_COLLATE
, 'en_US.UTF8')
24 home
= os
.path
.expanduser('~')
26 # Pull out the current set of words.
27 pws
= os
.path
.join(home
, '.aspell.en.pws')
28 with
open(pws
, encoding
='utf-8') as fp
:
29 lines
= [x
.strip() for x
in fp
.readlines()]
31 assert header
.startswith('personal_ws-1.1 en ')
32 words
= set(lines
[1:])
34 # Add any words from the user.
35 words
.update(opts
.words
)
37 # Update the aspell dict.
38 words
= sorted(words
, key
=locale
.strxfrm
)
39 header
= 'personal_ws-1.1 en %s ' % (len(words
),)
40 with
open(pws
, 'w', encoding
='utf-8') as fp
:
41 fp
.write(header
+ '\n')
42 fp
.write('\n'.join(words
) + '\n')
44 # Update Chrome's dict.
45 chrome_pws
= os
.path
.join(home
, '.config', 'google-chrome', 'Custom Dictionary.txt')
46 with
open(chrome_pws
, 'w', encoding
='utf-8') as fp
:
47 fp
.write('\n'.join(words
) + '\n')
50 if __name__
== '__main__':
51 sys
.exit(main(sys
.argv
[1:]))