Skip to content

Instantly share code, notes, and snippets.

@dunhamsteve
Last active July 19, 2023 01:55
Show Gist options
  • Save dunhamsteve/8ec07ada9df679f7308463700bb40eb2 to your computer and use it in GitHub Desktop.
Save dunhamsteve/8ec07ada9df679f7308463700bb40eb2 to your computer and use it in GitHub Desktop.
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