aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/keyboard.py
diff options
context:
space:
mode:
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 89f9346c4..0168d17ef 100644
--- a/lib/python/qmk/keyboard.py
+++ b/lib/python/qmk/keyboard.py
@@ -9,7 +9,7 @@ from glob import glob
9from qmk.c_parse import parse_config_h_file 9from qmk.c_parse import parse_config_h_file
10from qmk.json_schema import json_load 10from qmk.json_schema import json_load
11from qmk.makefile import parse_rules_mk_file 11from qmk.makefile import parse_rules_mk_file
12from qmk.path import is_keyboard 12from qmk.path import is_keyboard, under_qmk_firmware
13 13
14BOX_DRAWING_CHARACTERS = { 14BOX_DRAWING_CHARACTERS = {
15 "unicode": { 15 "unicode": {
@@ -33,6 +33,24 @@ BOX_DRAWING_CHARACTERS = {
33base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep 33base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep
34 34
35 35
36def find_keyboard_from_dir():
37 """Returns a keyboard name based on the user's current directory.
38 """
39 relative_cwd = under_qmk_firmware()
40
41 if relative_cwd and len(relative_cwd.parts) > 1 and relative_cwd.parts[0] == 'keyboards':
42 # Attempt to extract the keyboard name from the current directory
43 current_path = Path('/'.join(relative_cwd.parts[1:]))
44
45 if 'keymaps' in current_path.parts:
46 # Strip current_path of anything after `keymaps`
47 keymap_index = len(current_path.parts) - current_path.parts.index('keymaps') - 1
48 current_path = current_path.parents[keymap_index]
49
50 if is_keyboard(current_path):
51 return str(current_path)
52
53
36def keyboard_folder(keyboard): 54def keyboard_folder(keyboard):
37 """Returns the actual keyboard folder. 55 """Returns the actual keyboard folder.
38 56
@@ -61,6 +79,12 @@ def _find_name(path):
61 return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "") 79 return path.replace(base_path, "").replace(os.path.sep + "rules.mk", "")
62 80
63 81
82def keyboard_completer(prefix, action, parser, parsed_args):
83 """Returns a list of keyboards for tab completion.
84 """
85 return list_keyboards()
86
87
64def list_keyboards(): 88def list_keyboards():
65 """Returns a list of all keyboards. 89 """Returns a list of all keyboards.
66 """ 90 """