2019-09-10 05:14:25 -07:00
|
|
|
"""This script automates the copying of the default keymap into your own keymap.
|
|
|
|
"""
|
|
|
|
import shutil
|
|
|
|
|
2022-12-03 04:04:06 -08:00
|
|
|
from milc import cli
|
|
|
|
from milc.questions import question
|
|
|
|
|
2023-05-18 23:05:43 -07:00
|
|
|
from qmk.path import is_keyboard, keymaps, keymap
|
2022-12-03 04:04:06 -08:00
|
|
|
from qmk.git import git_get_username
|
2020-03-13 15:47:04 -07:00
|
|
|
from qmk.decorators import automagic_keyboard, automagic_keymap
|
2021-04-14 19:00:22 -07:00
|
|
|
from qmk.keyboard import keyboard_completer, keyboard_folder
|
2022-12-03 04:04:06 -08:00
|
|
|
|
|
|
|
|
|
|
|
def prompt_keyboard():
|
|
|
|
prompt = """{fg_yellow}Select Keyboard{style_reset_all}
|
|
|
|
If you`re unsure you can view a full list of supported keyboards with {fg_yellow}qmk list-keyboards{style_reset_all}.
|
|
|
|
|
|
|
|
Keyboard Name? """
|
|
|
|
|
|
|
|
return question(prompt)
|
|
|
|
|
|
|
|
|
|
|
|
def prompt_user():
|
|
|
|
prompt = """
|
|
|
|
{fg_yellow}Name Your Keymap{style_reset_all}
|
|
|
|
Used for maintainer, copyright, etc
|
|
|
|
|
|
|
|
Your GitHub Username? """
|
|
|
|
return question(prompt, default=git_get_username())
|
2019-09-10 05:14:25 -07:00
|
|
|
|
|
|
|
|
2021-04-14 19:00:22 -07:00
|
|
|
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
|
2019-09-22 13:25:33 -07:00
|
|
|
@cli.argument('-km', '--keymap', help='Specify the name for the new keymap directory')
|
|
|
|
@cli.subcommand('Creates a new keymap for the keyboard of your choosing')
|
2020-03-13 15:47:04 -07:00
|
|
|
@automagic_keyboard
|
|
|
|
@automagic_keymap
|
2019-09-22 13:25:33 -07:00
|
|
|
def new_keymap(cli):
|
2019-09-10 05:14:25 -07:00
|
|
|
"""Creates a new keymap for the keyboard of your choosing.
|
|
|
|
"""
|
2022-12-03 04:04:06 -08:00
|
|
|
cli.log.info('{style_bright}Generating a new keymap{style_normal}')
|
|
|
|
cli.echo('')
|
2019-09-10 05:14:25 -07:00
|
|
|
|
2022-12-03 04:04:06 -08:00
|
|
|
# ask for user input if keyboard or keymap was not provided in the command line
|
|
|
|
kb_name = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else prompt_keyboard()
|
|
|
|
user_name = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else prompt_user()
|
2019-09-10 05:14:25 -07:00
|
|
|
|
|
|
|
# check directories
|
2022-12-03 04:04:06 -08:00
|
|
|
if not is_keyboard(kb_name):
|
|
|
|
cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} does not exist! Please choose a valid name.')
|
2020-10-06 16:46:10 -07:00
|
|
|
return False
|
2020-02-17 11:42:11 -08:00
|
|
|
|
2022-12-03 04:04:06 -08:00
|
|
|
# generate keymap paths
|
2023-05-18 23:05:43 -07:00
|
|
|
keymaps_dirs = keymaps(kb_name)
|
|
|
|
keymap_path_default = keymap(kb_name, 'default')
|
|
|
|
keymap_path_new = keymaps_dirs[0] / user_name
|
2022-12-03 04:04:06 -08:00
|
|
|
|
2020-02-17 11:42:11 -08:00
|
|
|
if not keymap_path_default.exists():
|
2022-12-03 04:04:06 -08:00
|
|
|
cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
|
2020-10-06 16:46:10 -07:00
|
|
|
return False
|
2020-02-17 11:42:11 -08:00
|
|
|
|
|
|
|
if keymap_path_new.exists():
|
2022-12-03 04:04:06 -08:00
|
|
|
cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
|
2020-10-06 16:46:10 -07:00
|
|
|
return False
|
2019-09-10 05:14:25 -07:00
|
|
|
|
|
|
|
# create user directory with default keymap files
|
2020-04-18 13:00:56 -07:00
|
|
|
shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
|
2019-09-10 05:14:25 -07:00
|
|
|
|
|
|
|
# end message to user
|
2022-12-03 04:04:06 -08:00
|
|
|
cli.log.info(f'{{fg_green}}Created a new keymap called {{fg_cyan}}{user_name}{{fg_green}} in: {{fg_cyan}}{keymap_path_new}.{{fg_reset}}')
|
|
|
|
cli.log.info(f"Compile a firmware with your new keymap by typing: {{fg_yellow}}qmk compile -kb {kb_name} -km {user_name}{{fg_reset}}.")
|