Align new-keymap with new-keyboard (#19229)

master
Joel Challis 2022-12-03 12:04:06 +00:00 committed by GitHub
parent 82760bcea6
commit 32dabd5320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 18 deletions

View File

@ -28,7 +28,7 @@ If you did not configure your environment, or you have multiple keyboards, you c
Look at the output from that command, you should see something like this: Look at the output from that command, you should see something like this:
Ψ <github_username> keymap directory created in: /home/me/qmk_firmware/keyboards/clueboard/66/rev3/keymaps/<github_username> Ψ Created a new keymap called <github_username> in: /home/me/qmk_firmware/keyboards/clueboard/66/rev3/keymaps/<github_username>.
This is the location of your new `keymap.c` file. This is the location of your new `keymap.c` file.

View File

@ -1,12 +1,32 @@
"""This script automates the copying of the default keymap into your own keymap. """This script automates the copying of the default keymap into your own keymap.
""" """
import shutil import shutil
from pathlib import Path
import qmk.path from milc import cli
from milc.questions import question
from qmk.path import is_keyboard, keymap
from qmk.git import git_get_username
from qmk.decorators import automagic_keyboard, automagic_keymap from qmk.decorators import automagic_keyboard, automagic_keymap
from qmk.keyboard import keyboard_completer, keyboard_folder from qmk.keyboard import keyboard_completer, keyboard_folder
from milc import cli
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())
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse') @cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Specify keyboard name. Example: 1upkeyboards/1up60hse')
@ -17,32 +37,34 @@ from milc import cli
def new_keymap(cli): def new_keymap(cli):
"""Creates a new keymap for the keyboard of your choosing. """Creates a new keymap for the keyboard of your choosing.
""" """
# ask for user input if keyboard or keymap was not provided in the command line cli.log.info('{style_bright}Generating a new keymap{style_normal}')
keyboard = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else input("Keyboard Name: ") cli.echo('')
keymap = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else input("Keymap Name: ")
# generate keymap paths # ask for user input if keyboard or keymap was not provided in the command line
kb_path = Path('keyboards') / keyboard kb_name = cli.config.new_keymap.keyboard if cli.config.new_keymap.keyboard else prompt_keyboard()
keymap_path = qmk.path.keymap(keyboard) user_name = cli.config.new_keymap.keymap if cli.config.new_keymap.keymap else prompt_user()
keymap_path_default = keymap_path / 'default'
keymap_path_new = keymap_path / keymap
# check directories # check directories
if not kb_path.exists(): if not is_keyboard(kb_name):
cli.log.error('Keyboard %s does not exist!', kb_path) cli.log.error(f'Keyboard {{fg_cyan}}{kb_name}{{fg_reset}} does not exist! Please choose a valid name.')
return False return False
# generate keymap paths
km_path = keymap(kb_name)
keymap_path_default = km_path / 'default'
keymap_path_new = km_path / user_name
if not keymap_path_default.exists(): if not keymap_path_default.exists():
cli.log.error('Keyboard default %s does not exist!', keymap_path_default) cli.log.error(f'Default keymap {{fg_cyan}}{keymap_path_default}{{fg_reset}} does not exist!')
return False return False
if keymap_path_new.exists(): if keymap_path_new.exists():
cli.log.error('Keymap %s already exists!', keymap_path_new) cli.log.error(f'Keymap {{fg_cyan}}{user_name}{{fg_reset}} already exists! Please choose a different name.')
return False return False
# create user directory with default keymap files # create user directory with default keymap files
shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True) shutil.copytree(keymap_path_default, keymap_path_new, symlinks=True)
# end message to user # end message to user
cli.log.info("%s keymap directory created in: %s", keymap, keymap_path_new) 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("Compile a firmware with your new keymap by typing: \n\n\tqmk compile -kb %s -km %s\n", keyboard, keymap) 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}}.")