Fix shell execution in "zmk code" command#49
Merged
joelspadin merged 2 commits intozmkfirmware:mainfrom Jan 5, 2026
Merged
Conversation
Running a command in a POSIX shell requires it be a string instead of a list, but quoting syntax differs between POSIX and non-POSIX shells, so there is no shell-agnostic way to do that. Instead, we now look up the first argument in PATH directories like a shell would, then run the command without a shell. Fixes zmkfirmware#27
To simplify parsing, the "zmk config" command was switched long ago from expecting a single "variable=value" argument to having the variable and value passed as separate arguments. Some of the "zmk code" command output still referenced the old format. This fixes that.
caksoylar
reviewed
Jan 5, 2026
| from pathlib import Path | ||
|
|
||
|
|
||
| def get_subprocess_args(cmd: list[str | Path]) -> list[str | Path]: |
Contributor
There was a problem hiding this comment.
Is this to be able to use executables from PATH (which shell=True did before)?
edit: seems so from the docstring below.
Collaborator
Author
There was a problem hiding this comment.
Yeah. When you don't pass a path argument to shutil.which(), it searches PATH: https://docs.python.org/3/library/shutil.html#shutil.which
caksoylar
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While the Python documentation states
it seems to be more of a requirement than a recommendation on Linux. To fix this, instead of launching the editor using a shell command, we now use
shutil.which()to get the full path to the executable as if it were running in a shell, then run it as a normal process (with the args remaining as a list) instead of in a shell.This supersedes #30
Also fixed an issue with
zmk codewhere it printed invalidzmk config ...commands.