mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 04:55:20 -05:00
This deletes the Bash and PowerShell setup scripts in favor of using ZMK CLI. The old setup scripts are broken, since the config repo template uses ZMK version 0.3, while the setup scripts use hardware metadata from the main branch. ZMK CLI doesn't have this issue, because it clones the version of ZMK listed in the config repo to get hardware metadata. Much of the "Installing ZMK" page has been rewritten to give instructions for installing ZMK CLI and using it to create and modify a config repo. The previously-hidden page on ZMK CLI has been added to the sidebar and repurposed into general documentation for the tool.
146 lines
6.7 KiB
Plaintext
146 lines
6.7 KiB
Plaintext
---
|
|
title: ZMK CLI
|
|
sidebar_label: ZMK CLI
|
|
---
|
|
|
|
ZMK CLI is a command line tool which helps with setting up a ZMK config repo and automates some common tasks such as adding new keyboards to your repository.
|
|
|
|
See the [ZMK installation guide](user-setup.mdx#prerequisites) for instructions on installing ZMK CLI.
|
|
|
|
## Using ZMK CLI
|
|
|
|
The instructions below contain commands that need to be run in a terminal program.
|
|
|
|
- On Windows, use [Windows Terminal](https://apps.microsoft.com/detail/9n0dx20hk701) or PowerShell.
|
|
- On other operating systems, the terminal program is usually just named "Terminal".
|
|
|
|
All ZMK CLI commands start with `zmk`. Run `zmk --help` for general usage instructions. For help with a specific subcommand, add `--help` after the subcommand, e.g. `zmk init --help`.
|
|
|
|
### Initialize a Repository
|
|
|
|
The `zmk init` command walks you through creating a GitHub repository, then clones it to your computer so you can edit it. See the [ZMK installation guide](user-setup.mdx#config-repo-setup) for more details on this command.
|
|
|
|
### Keyboard Management
|
|
|
|
#### Add a keyboard
|
|
|
|
To start building firmware for a new keyboard, run `zmk keyboard add`. Follow the instructions to select a keyboard (and controller board if necessary), and it will add it to the list of firmware to build and copy a default keymap into your repo.
|
|
|
|
You can then run `zmk code <keyboard>` to open the keymap in a text editor.
|
|
|
|
This command reads from a local copy of ZMK to determine the supported keyboards. If the keyboard you want to use isn't listed, try running `zmk update` to update the local copy to the latest version of ZMK. If it still isn't listed, you may be able to find a [Zephyr module](#module-management) that provides it, or you may need to [create it yourself](#create-a-new-keyboard).
|
|
|
|
#### Remove a keyboard
|
|
|
|
To remove a keyboard from the build, run `zmk keyboard remove` and select the item to remove. For a split keyboard, you will need to run this twice and remove the left and right sides.
|
|
|
|
This simply removes a keyboard from the `build.yaml` file. It does not delete any `.keymap` or `.conf` files.
|
|
|
|
#### List supported keyboards
|
|
|
|
Run `zmk keyboard list` to print a list of supported keyboard hardware.
|
|
|
|
#### Create a new keyboard
|
|
|
|
If ZMK doesn't support your keyboard yet, you can run `zmk keyboard new` to create a new keyboard from a template.
|
|
|
|
This won't walk you through all of the details of adding support for a new keyboard, but it will generate most of the boilerplate for you. See the [New Keyboard Shield](development/hardware-integration/new-shield.mdx) guide for how to finish writing the keyboard files.
|
|
|
|
### Module Management
|
|
|
|
[Modules](features/modules.mdx) can add support for new keyboards, behaviors, and other features to ZMK. Use the `zmk module` command to install modules into your repo:
|
|
|
|
```sh
|
|
zmk module add # Add a module
|
|
zmk module add <url> # Add a module given the URL of the repo
|
|
zmk module remove # Remove an installed module
|
|
zmk module list # List the installed modules
|
|
zmk update # Update the local copies of ZMK and modules to their latest versions
|
|
```
|
|
|
|
:::note
|
|
|
|
ZMK CLI stores a copy of ZMK and any modules in a `.zmk` folder so it can read board and shield information from them. This folder is only used by ZMK CLI and is not necessary for building firmware, therefore ZMK CLI will automatically add it to your repo's `.gitignore` file.
|
|
|
|
:::
|
|
|
|
### Edit Keymap and Config Files
|
|
|
|
The `zmk code` command will open ZMK files in a text editor:
|
|
|
|
```sh
|
|
zmk code # Open the repo directory in an editor
|
|
zmk code <keyboard> # Open <keyboard>.keymap in an editor
|
|
zmk code --conf <keyboard> # Open <keyboard>.conf in an editor
|
|
zmk code --build # Open build.yaml in an editor
|
|
```
|
|
|
|
The first time you run this command, it will ask you which editor you want to use. If you want to change this choice later or use an editor that wasn't listed, see the [core.editor](#coreeditor) and [code.explorer](#coreexplorer) settings.
|
|
|
|
### Push Changes to GitHub
|
|
|
|
Run `zmk cd` to go to the repo directory. From here, you can run `git` commands manage the repo.
|
|
|
|
For example, after adding a keyboard to your repo and editing its keymap, you can run the following commands to push your changes to GitHub and trigger a firmware build:
|
|
|
|
```sh
|
|
git add .
|
|
git commit
|
|
git push
|
|
```
|
|
|
|
You will need to [authenticate with GitHub](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#authenticating-with-the-command-line) before the `git push` command will work. The easiest way to do this is to install the [GitHub CLI](https://cli.github.com/) and run
|
|
|
|
```sh
|
|
gh auth login
|
|
```
|
|
|
|
but you can also use a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens). If using an access token, make sure you create it with the "workflow" scope option selected.
|
|
|
|
### Download Firmware from GitHub
|
|
|
|
After pushing changes, GitHub will automatically build the firmware for you. Run `zmk download` (or `zmk dl` for short) to open the GitHub actions page in your browser.
|
|
|
|
From this page, you can click on a build (the latest is at the top) to view its status. If the build succeeded, you can download the firmware from the "Artifacts" section at the bottom of the build summary page.
|
|
|
|
### Configuration
|
|
|
|
The `zmk config` command manages settings for ZMK CLI:
|
|
|
|
```sh
|
|
zmk config # List all settings
|
|
zmk config <name> # Print the value of the setting <name>
|
|
zmk config <name> <value> # Set <name> to <value>
|
|
zmk config --unset <name> # Remove the setting <name>
|
|
```
|
|
|
|
By default, these settings are stored in a file in your user profile directory. Run `zmk config --path` to get the location of this file. You can change where the settings file is stored by setting a `ZMK_CLI_CONFIG` environment variable to the new path to use, or by adding a `--config-file=<path>` argument when running `zmk`.
|
|
|
|
Other commands use the following settings:
|
|
|
|
#### user.home
|
|
|
|
The path to the repository to use whenever `zmk` is run and the working directory is not inside a ZMK config repository.
|
|
|
|
For example, to point ZMK CLI to an existing repo at `~/Documents/zmk-config`, run:
|
|
|
|
```sh
|
|
zmk config user.home ~/Documents/zmk-config
|
|
```
|
|
|
|
#### core.editor
|
|
|
|
Command line for a text editor to use with the `zmk code` command.
|
|
|
|
For example, so set Visual Studio Code as the editor and make it always open a new window, run:
|
|
|
|
```sh
|
|
zmk config core.editor "code --new-window"
|
|
```
|
|
|
|
#### core.explorer
|
|
|
|
Command line for a file explorer to use with the `zmk code` command when opening a directory.
|
|
|
|
If this setting is not set, the `core.editor` tool will be run instead. Set this setting when using a text editor that does not support opening directories.
|