See https://github.com/zsa/qmk_firmware/ for instructions on how to build and flash firmware.
Last active
August 21, 2021 13:41
-
-
Save Mononofu/5170ee3fdfab861c38a6828323839ee9 to your computer and use it in GitHub Desktop.
Converts Moonlander unicode entry macros from MacOS format (as generated by Oryx) to the corresponding Linux key-combinations.
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
#!/usr/bin/python3 | |
import argparse | |
import os | |
import re | |
import subprocess | |
import zipfile | |
def main(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--source", required=True, help="The firmware source downloaded from Oryx." | |
) | |
parser.add_argument( | |
"--firmware_root", | |
required=True, | |
help="QMK / Moonlander firmware root directory.", | |
) | |
args = parser.parse_args() | |
with zipfile.ZipFile(args.source) as zip: | |
# Parse the source .zip file downloaded from Oryx. | |
for path in zip.namelist(): | |
match = re.match(r"moonlander_([\w-]+)_source/.+", path) | |
if not match: | |
continue | |
# Determine the name of the layout and its target path in the | |
# firmware directory. | |
name = match.group(1) | |
layout_dir = os.path.join( | |
args.firmware_root, "keyboards/moonlander/keymaps", name | |
) | |
if not os.path.exists(layout_dir): | |
os.makedirs(layout_dir) | |
with open(os.path.join(layout_dir, os.path.basename(path)), "w") as f: | |
contents = zip.read(path).decode('utf-8') | |
# Rewrite MacOS unicode input to X11/Linux unicode input. | |
contents = re.sub(r'SEND_STRING\(SS_LALT\(((SS_TAP\(X_[0-9A-F]\) )+)\)\);', | |
r'SEND_STRING(SS_LCTL(SS_LSFT(SS_TAP(X_U))) \1 SS_TAP(X_ENTER));', | |
contents) | |
f.write(contents) | |
subprocess.run(f'qmk compile -j {os.cpu_count()} -kb moonlander -km {name}', shell=True) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment