diff options
author | Nick Brassel <nick@tzarc.org> | 2021-11-05 08:55:55 +1100 |
---|---|---|
committer | Nick Brassel <nick@tzarc.org> | 2021-11-05 08:55:55 +1100 |
commit | 92e9bbd9b9c83553f5c9060cbcdb5c44e9eddb79 (patch) | |
tree | 2ccfc6ff2317d94d02e2a3f25db0ec383de32032 | |
parent | 84ea77ead663624a6d8ae451ca3d4318008d9d41 (diff) | |
parent | c8da63382c7d2cc0de13559c10b5fde0f436f9e3 (diff) | |
download | qmk_firmware-92e9bbd9b9c83553f5c9060cbcdb5c44e9eddb79.tar.gz qmk_firmware-92e9bbd9b9c83553f5c9060cbcdb5c44e9eddb79.zip |
Merge remote-tracking branch 'upstream/master' into develop
-rw-r--r-- | docs/cli_commands.md | 62 | ||||
-rw-r--r-- | lib/python/qmk/cli/__init__.py | 1 | ||||
-rwxr-xr-x | lib/python/qmk/cli/cd.py | 46 | ||||
-rw-r--r-- | lib/python/qmk/info.py | 12 |
4 files changed, 117 insertions, 4 deletions
diff --git a/docs/cli_commands.md b/docs/cli_commands.md index 9113e3b02..520da06c4 100644 --- a/docs/cli_commands.md +++ b/docs/cli_commands.md | |||
@@ -118,6 +118,68 @@ This command lets you configure the behavior of QMK. For the full `qmk config` d | |||
118 | qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN] | 118 | qmk config [-ro] [config_token1] [config_token2] [...] [config_tokenN] |
119 | ``` | 119 | ``` |
120 | 120 | ||
121 | ## `qmk cd` | ||
122 | |||
123 | This command opens a new shell in your `qmk_firmware` directory. | ||
124 | |||
125 | Note that if you are already somewhere within `QMK_HOME` (for example, the `keyboards/` folder), nothing will happen. | ||
126 | |||
127 | To exit out into the parent shell, simply type `exit`. | ||
128 | |||
129 | **Usage**: | ||
130 | |||
131 | ``` | ||
132 | qmk cd | ||
133 | ``` | ||
134 | |||
135 | ## `qmk console` | ||
136 | |||
137 | This command lets you connect to keyboard consoles to get debugging messages. It only works if your keyboard firmware has been compiled with `CONSOLE_ENABLE=yes`. | ||
138 | |||
139 | **Usage**: | ||
140 | |||
141 | ``` | ||
142 | qmk console [-d <pid>:<vid>[:<index>]] [-l] [-n] [-t] [-w <seconds>] | ||
143 | ``` | ||
144 | |||
145 | **Examples**: | ||
146 | |||
147 | Connect to all available keyboards and show their console messages: | ||
148 | |||
149 | ``` | ||
150 | qmk console | ||
151 | ``` | ||
152 | |||
153 | List all devices: | ||
154 | |||
155 | ``` | ||
156 | qmk console -l | ||
157 | ``` | ||
158 | |||
159 | Show only messages from clueboard/66/rev3 keyboards: | ||
160 | |||
161 | ``` | ||
162 | qmk console -d C1ED:2370 | ||
163 | ``` | ||
164 | |||
165 | Show only messages from the second clueboard/66/rev3: | ||
166 | |||
167 | ``` | ||
168 | qmk console -d C1ED:2370:2 | ||
169 | ``` | ||
170 | |||
171 | Show timestamps and VID:PID instead of names: | ||
172 | |||
173 | ``` | ||
174 | qmk console -n -t | ||
175 | ``` | ||
176 | |||
177 | Disable bootloader messages: | ||
178 | |||
179 | ``` | ||
180 | qmk console --no-bootloaders | ||
181 | ``` | ||
182 | |||
121 | ## `qmk doctor` | 183 | ## `qmk doctor` |
122 | 184 | ||
123 | This command examines your environment and alerts you to potential build or flash problems. It can fix many of them if you want it to. | 185 | This command examines your environment and alerts you to potential build or flash problems. It can fix many of them if you want it to. |
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py index 094ea80b8..edf351d62 100644 --- a/lib/python/qmk/cli/__init__.py +++ b/lib/python/qmk/cli/__init__.py | |||
@@ -31,6 +31,7 @@ safe_commands = [ | |||
31 | subcommands = [ | 31 | subcommands = [ |
32 | 'qmk.cli.bux', | 32 | 'qmk.cli.bux', |
33 | 'qmk.cli.c2json', | 33 | 'qmk.cli.c2json', |
34 | 'qmk.cli.cd', | ||
34 | 'qmk.cli.cformat', | 35 | 'qmk.cli.cformat', |
35 | 'qmk.cli.chibios.confmigrate', | 36 | 'qmk.cli.chibios.confmigrate', |
36 | 'qmk.cli.clean', | 37 | 'qmk.cli.clean', |
diff --git a/lib/python/qmk/cli/cd.py b/lib/python/qmk/cli/cd.py new file mode 100755 index 000000000..c62c3f56c --- /dev/null +++ b/lib/python/qmk/cli/cd.py | |||
@@ -0,0 +1,46 @@ | |||
1 | """Open a shell in the QMK Home directory | ||
2 | """ | ||
3 | import sys | ||
4 | import os | ||
5 | |||
6 | from milc import cli | ||
7 | |||
8 | from qmk.path import under_qmk_firmware | ||
9 | |||
10 | |||
11 | @cli.subcommand('Go to QMK Home') | ||
12 | def cd(cli): | ||
13 | """Go to QMK Home | ||
14 | """ | ||
15 | if not sys.stdout.isatty(): | ||
16 | cli.log.error("This command is for interactive usage only. For non-interactive usage, 'cd $(qmk env QMK_HOME)' is more robust.") | ||
17 | sys.exit(1) | ||
18 | |||
19 | if not under_qmk_firmware(): | ||
20 | # Only do anything if the user is not under qmk_firmware already | ||
21 | # in order to reduce the possibility of starting multiple shells | ||
22 | cli.log.info("Spawning a subshell in your QMK_HOME directory.") | ||
23 | cli.log.info("Type 'exit' to get back to the parent shell.") | ||
24 | if not cli.platform.lower().startswith('windows'): | ||
25 | # For Linux/Mac/etc | ||
26 | # Check the user's login shell from 'passwd' | ||
27 | # alternatively fall back to $SHELL env var | ||
28 | # and finally to '/bin/bash'. | ||
29 | import getpass | ||
30 | import pwd | ||
31 | shell = pwd.getpwnam(getpass.getuser()).pw_shell | ||
32 | if not shell: | ||
33 | shell = os.environ.get('SHELL', '/bin/bash') | ||
34 | # Start the new subshell | ||
35 | os.execl(shell, shell) | ||
36 | else: | ||
37 | # For Windows | ||
38 | # Check the $SHELL env var | ||
39 | # and fall back to '/usr/bin/bash'. | ||
40 | qmk_env = os.environ.copy() | ||
41 | # Set the prompt for the new shell | ||
42 | qmk_env['MSYS2_PS1'] = qmk_env['PS1'] | ||
43 | # Start the new subshell | ||
44 | cli.run([os.environ.get('SHELL', '/usr/bin/bash')], env=qmk_env) | ||
45 | else: | ||
46 | cli.log.info("Already within qmk_firmware directory.") | ||
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index d81f30438..dc42fdd4d 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
@@ -25,6 +25,13 @@ def _valid_community_layout(layout): | |||
25 | return (Path('layouts/default') / layout).exists() | 25 | return (Path('layouts/default') / layout).exists() |
26 | 26 | ||
27 | 27 | ||
28 | def _remove_newlines_from_labels(layouts): | ||
29 | for layout_name, layout_json in layouts.items(): | ||
30 | for key in layout_json['layout']: | ||
31 | if '\n' in key['label']: | ||
32 | key['label'] = key['label'].split('\n')[0] | ||
33 | |||
34 | |||
28 | def info_json(keyboard): | 35 | def info_json(keyboard): |
29 | """Generate the info.json data for a specific keyboard. | 36 | """Generate the info.json data for a specific keyboard. |
30 | """ | 37 | """ |
@@ -100,10 +107,7 @@ def info_json(keyboard): | |||
100 | _check_matrix(info_data) | 107 | _check_matrix(info_data) |
101 | 108 | ||
102 | # Remove newline characters from layout labels | 109 | # Remove newline characters from layout labels |
103 | for layout_name, layout_json in layouts.items(): | 110 | _remove_newlines_from_labels(layouts) |
104 | for key in layout_json['layout']: | ||
105 | if '\n' in key['label']: | ||
106 | key['label'] = key['label'].split('\n')[0] | ||
107 | 111 | ||
108 | return info_data | 112 | return info_data |
109 | 113 | ||