Skip to main content

A command line program to help set up ZMK Firmware

Project description

ZMK CLI

A command line program to help set up ZMK Firmware.

ZMK CLI walks you through installing ZMK and setting up a GitHub repository to store and build custom firmware. It also automates some common tasks such as adding new keyboards to your repository.

The instructions below contain commands that need to be run in a terminal program. On Windows, use the Windows Terminal or PowerShell. On other operating systems, the terminal program is usually just named "Terminal".

Installation

Install Git

Install Git from https://git-scm.com/downloads.

If you have Windows 11, you can instead open a terminal and run:

winget install git.git

Install Python

ZMK CLI requires Python 3.10 or newer.

On Windows and macOS

Install the latest version of Python from https://www.python.org/downloads/.

If you have Windows 11, you can instead open a terminal and run:

winget install python3

On Linux

Most Linux distributions come with Python already installed. Open a terminal and run the following command to check its version:

python3 --version

If Python is not installed, install python3 with your package manager.

If the version is older than 3.10, you will need to find and install a package for a newer version of Python. On Ubuntu 20.04 and older, you can get Python 3.10 from the deadsnakes PPA with the following commands:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.10

You will then need to replace python3 with python3.10 in the rest of the installation instructions.

Install pipx

ZMK CLI can be installed with pip, but using pipx is recommended to avoid conflicts between Python packages.

On Windows and Linux

Open a terminal and run:

python3 -m pip install --user pipx
python3 -m pipx ensurepath

Some Linux distributions may disallow installing packages with pip. If this gives you an error, see the install instructions specific to your distribution.

Close and reopen your terminal, then run the following command. It should print a version number if everything is installed correctly:

pipx --version

On macOS

Open Terminal and run:

brew install pipx
pipx ensurepath

Install ZMK CLI

Next, run the following commands:

pipx install zmk
zmk --help

It should print a help message if everything installed correctly.

On Linux, you may get an error saying you need to install another package such as python3.10-venv. If so, follow the instructions in the error message, then try the above commands again.

Usage

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

⚠️ If you have already created a repo and cloned it to your computer, you do not need to run this command. Set the user.home setting to point to the existing repo instead.

The zmk init command walks you through creating a GitHub repository, then clones it to your computer so you can edit it.

Open a terminal and use the cd command to move to a directory where you'd like to place the ZMK files, then run zmk init. For example:

cd ~/Documents
zmk init

Follow the instructions it gives you. If you already have a ZMK config repo, you can enter its URL when prompted, for example:

Repository URL: https://github.com/myusername/zmk-config

Otherwise, leave this first prompt blank and press Enter, and it will walk you through creating a new repo.

Once you finish following all the instructions, you will have a copy of the repo stored on your computer. All zmk commands will run on this repo (unless the working directory is inside a different repo). If you ever forget where the repo is located, you can run zmk cd to find it.

Now that you have a repo created, see Customizing ZMK for documentation on how to customize it, and see the instructions below for how ZMK CLI can automate some common tasks.

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 that provides it, or you may need to create it yourself.

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 guide for how to finish writing the keyboard files.

Module Management

Zephyr modules can add support for new keyboards, behaviors, and other features to ZMK. Use the zmk module command to install modules into your repo:

zmk module add     # Add a module
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

Edit Keymap and Config Files

The zmk code command will open ZMK files in a text editor:

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 and code.explorer 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:

git add .
git commit
git push

You will need to authenticate with GitHub before the git push command will work. The easiest way to do this is to install the GitHub CLI and run

gh auth login

but you can also use a personal access token. 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:

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:

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:

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.

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:

zmk config user.home ~/Documents/zmk-config

Development

If you would like to help improve ZMK CLI, you can clone this repo and install it in editable mode so your changes to the code apply when you run zmk. Open a terminal to the root directory of the repository and run:

pip install -e ".[dev]"
pre-commit install

You may optionally run these commands inside a virtual environment if you don't want to install ZMK CLI's dependencies globally or if your OS disallows doing this.

After running pre-commit install, your code will be checked when you make a commit, but there are some slower checks that do not run automatically. To run these additional checks, run these commands:

pyright .
pylint zmk

Alternatively, you can just create a pull request and GitHub will run the checks and report any errors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zmk-0.2.0.tar.gz (53.9 kB view details)

Uploaded Source

Built Distribution

zmk-0.2.0-py3-none-any.whl (81.3 kB view details)

Uploaded Python 3

File details

Details for the file zmk-0.2.0.tar.gz.

File metadata

  • Download URL: zmk-0.2.0.tar.gz
  • Upload date:
  • Size: 53.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zmk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e71266b400117cf30e275bfc33a99651a95a57c3d4298f62ad6b16431e317b2
MD5 e401b52a023add3c04a69b076f80a2e7
BLAKE2b-256 9c882f51408f424ff592c3278cf903a9dc001b156a155711f332333a8062b956

See more details on using hashes here.

File details

Details for the file zmk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: zmk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 81.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zmk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fca0c844b9de502496e13118b981f037176320e2dc6da92d26615794a526a6ef
MD5 a92830c637ca0da04d38c13452965311
BLAKE2b-256 63a4305925295d8dc33246f44f9aef3089a661213e0a0dd883c19c1abfbe69a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page