keymap.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """This script automates the copying of the default keymap into your own keymap.
  2. """
  3. import shutil
  4. from pathlib import Path
  5. import qmk.path
  6. from qmk.decorators import automagic_keyboard, automagic_keymap
  7. from qmk.keyboard import keyboard_completer, keyboard_folder
  8. from milc import cli
  9. @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
  10. @cli.argument('-km', '--keymap', help='Specify the name for the new keymap directory')
  11. @cli.subcommand('Creates a new keymap for the keyboard of your choosing')
  12. @automagic_keyboard
  13. @automagic_keymap
  14. def new_keymap(cli):
  15. """Creates a new keymap for the keyboard of your choosing.
  16. """
  17. # ask for user input if keyboard or keymap was not provided in the command line
  18. keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ")
  19. keymap = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else input("Keymap Name: ")
  20. # generate keymap paths
  21. kb_path = Path('keyboards') / keyboard
  22. keymap_path = qmk.path.keymap(keyboard)
  23. keymap_path_default = keymap_path / 'default'
  24. keymap_path_new = keymap_path / keymap
  25. # check directories
  26. if not kb_path.exists():
  27. cli.log.error('Keyboard %s does not exist!', kb_path)
  28. return False
  29. if not keymap_path_default.exists():
  30. cli.log.error('Keyboard default %s does not exist!', keymap_path_default)
  31. return False
  32. if keymap_path_new.exists():
  33. cli.log.error('Keymap %s already exists!', keymap_path_new)
  34. return False
  35. # create user directory with default keymap files
  36. shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
  37. # end message to user
  38. cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new)
  39. cli.log.info("Compile a firmware with your new keymap by typing: \n\n\tqmk compile -kb %s -km %s\n", keyboard, keymap)