Last active
July 19, 2023 01:55
-
-
Save dunhamsteve/8ec07ada9df679f7308463700bb40eb2 to your computer and use it in GitHub Desktop.
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
from yaml import Loader, load | |
# I got the idea from: | |
# https://github.com/Granitosaurus/macos-compose/tree/master | |
# in Karabiner, assign right_control to non_us_backslash (which somehow is §) | |
# | |
# in keys.yaml, lines like: | |
# §to: → | |
# §in: ∈ | |
# §ni: ∋ | |
# §all: ∀ | |
# §ex: ∃ | |
# §sum: ∑ | |
# §prod: ∏ | |
# §x: × | |
# §.: · | |
# §<: ⟨ | |
# §>: ⟩ | |
# | |
# python3 mk_bindings.py > ~/Library/KeyBindings/DefaultKeyBinding.dict | |
# | |
# and reload applications | |
# | |
data = load(open('keys.yaml'),Loader=Loader) | |
pfx = "" | |
bra = "{" | |
sp = "" | |
print("{") | |
for key in sorted(data.keys()): | |
while not key.startswith(pfx): | |
print(sp+"};") | |
pfx = pfx[:-1] | |
sp = " "*len(pfx) | |
while len(pfx) < len(key) - 1: | |
c = key[len(pfx)] | |
print(f'{sp}"{c}" = {bra}') | |
pfx += c | |
sp = " "*len(pfx) | |
c = key[len(pfx)] | |
print(f'{sp}"{c}" = ("insertText:", "{data[key]}");') | |
for _ in pfx: print("};") | |
print("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment