diff options
author | Zach White <skullydazed@gmail.com> | 2021-04-14 19:00:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 19:00:22 -0700 |
commit | 588bcdc8ca212b195a428fc43766a59a9252c08d (patch) | |
tree | 4867ef610b2178d51002063bd4913e806f771543 /lib/python/qmk/keyboard.py | |
parent | b33e6793de6c5f5124ee88fb3eb62d8f54f74940 (diff) | |
download | qmk_firmware-588bcdc8ca212b195a428fc43766a59a9252c08d.tar.gz qmk_firmware-588bcdc8ca212b195a428fc43766a59a9252c08d.zip |
Add support for tab completion (#12411)
* Add support for tab completion
* make flake8 happy
* Add documentation
Diffstat (limited to 'lib/python/qmk/keyboard.py')
-rw-r--r-- | lib/python/qmk/keyboard.py | 26 |
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 | |||
9 | from qmk.c_parse import parse_config_h_file | 9 | from qmk.c_parse import parse_config_h_file |
10 | from qmk.json_schema import json_load | 10 | from qmk.json_schema import json_load |
11 | from qmk.makefile import parse_rules_mk_file | 11 | from qmk.makefile import parse_rules_mk_file |
12 | from qmk.path import is_keyboard | 12 | from qmk.path import is_keyboard, under_qmk_firmware |
13 | 13 | ||
14 | BOX_DRAWING_CHARACTERS = { | 14 | BOX_DRAWING_CHARACTERS = { |
15 | "unicode": { | 15 | "unicode": { |
@@ -33,6 +33,24 @@ BOX_DRAWING_CHARACTERS = { | |||
33 | base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep | 33 | base_path = os.path.join(os.getcwd(), "keyboards") + os.path.sep |
34 | 34 | ||
35 | 35 | ||
36 | def 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 | |||
36 | def keyboard_folder(keyboard): | 54 | def 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 | ||
82 | def keyboard_completer(prefix, action, parser, parsed_args): | ||
83 | """Returns a list of keyboards for tab completion. | ||
84 | """ | ||
85 | return list_keyboards() | ||
86 | |||
87 | |||
64 | def list_keyboards(): | 88 | def list_keyboards(): |
65 | """Returns a list of all keyboards. | 89 | """Returns a list of all keyboards. |
66 | """ | 90 | """ |