]>
git.wh0rd.org - home.git/blob - .bin/aspell-sort-pws
3 """Update & sort personal dictionaries."""
7 from pathlib
import Path
13 """Return a CLI parser."""
14 parser
= argparse
.ArgumentParser(description
=__doc__
)
16 "--commit", action
="store_true", help="commit to git"
18 parser
.add_argument("words", nargs
="*", help="words to add to the dictionary")
24 opts
= parser
.parse_args(argv
)
27 locale
.setlocale(locale
.LC_COLLATE
, "en_US.UTF8")
31 # Pull out the current set of words.
32 # Strip any git conflicts to make things easier.
33 pws
= home
/ ".aspell.en.pws"
35 x
.strip() for x
in pws
.read_text(encoding
="utf-8").splitlines() if " " not in x
37 words
-= {"<<<<<<<", "|||||||", "=======", ">>>>>>>"}
39 # Add any words from the user.
40 words
.update(opts
.words
)
42 # Update the aspell dict.
43 words
= sorted(words
, key
=locale
.strxfrm
)
44 content
= "\n".join(words
) + "\n"
45 header
= f
"personal_ws-1.1 en {len(words)} \n"
46 with pws
.open("w", encoding
="utf-8") as fp
:
50 # Update Chrome's dict.
51 chrome_pws
= home
/ ".config" / "google-chrome" / "Custom Dictionary.txt"
52 chrome_pws
.write_text(content
, encoding
="utf-8")
56 ["git", "commit", "-m", "dict: add more words", pws
, chrome_pws
], cwd
=home
60 if __name__
== "__main__":
61 sys
.exit(main(sys
.argv
[1:]))