summaryrefslogtreecommitdiffstats
path: root/lib/python/qmk/keyboard.py
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-04-15 02:00:59 +0000
committerQMK Bot <hello@qmk.fm>2021-04-15 02:00:59 +0000
commit2c0aa27e6c0db68c026d2e8d1b416bac5e9599a5 (patch)
tree8b0bb8f960c3edb631e30d391eb69443c85c48c2 /lib/python/qmk/keyboard.py
parent19b143688fabcad7ffd192e56642232f1a08fdae (diff)
parent588bcdc8ca212b195a428fc43766a59a9252c08d (diff)
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib/python/qmk/keyboard.py')
-rw-r--r--lib/python/qmk/keyboard.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/python/qmk/keyboard.py b/lib/python/qmk/keyboard.py
index 89f9346c40..0168d17ef3 100644
--- a/lib/python/qmk/keyboard.py
+++ b/lib/python/qmk/keyboard.py
@@ -9,7 +9,7 @@ from glob import glob
from qmk.c_parse import parse_config_h_file
from qmk.json_schema import json_load
from qmk.makefile import parse_rules_mk_file
-from qmk.path import is_keyboard
+from qmk.path import is_keyboard, under_qmk_firmware
BOX_DRAWING_CHARACTERS = {
"unicode": {
@@ -33,6 +33,24 @@ BOX_DRAWING_CHARACTERS = {
base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
+def find_keyboard_from_dir():
+ """Returns a keyboard name based on the user's current directory.
+ """
+ relative_cwd = under_qmk_firmware()
+
+ if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards':
+ # Attempt to extract the keyboard name from the current directory
+ current_path = Path('/'.join(relative_cwd.parts[1:]))
+
+ if 'keymaps' in current_path.parts:
+ # Strip current_path of anything after `keymaps`
+ keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1
+ current_path = current_path.parents[keymap_index]
+
+ if is_keyboard(current_path):
+ return str(current_path)
+
+
def keyboard_folder(keyboard):
"""Returns the actual keyboard folder.
@@ -61,6 +79,12 @@ def _find_name(path):
return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "")
+def keyboard_completer(prefix, action, parser, parsed_args):
+ """Returns a list of keyboards for tab completion.
+ """
+ return list_keyboards()
+
+
def list_keyboards():
"""Returns a list of all keyboards.
"""