zmk_build

ZMK code & build repository
git clone https://git.pngu.org/zmk_build
Log | Files | Refs | Submodules | README

commit e634246abb8c63bc4f2d115fd62c1f2cd769849c
parent d301cf9000242b4cf02e170661758a2666f8b170
Author: Jack Sangdahl <jack@pngu.org>
Date:   Tue, 10 Feb 2026 10:13:05 -0700

Improvements to build script and readme

Diffstat:
Mbuild.sh | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mreadme.md | 13+++++++------
2 files changed, 65 insertions(+), 20 deletions(-)

diff --git a/build.sh b/build.sh @@ -1,32 +1,73 @@ #!/bin/sh + RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) BLUE=$(tput setaf 4) BOLD=$(tput bold) NORMAL=$(tput sgr0) + set -e -ZMK_DIR=$HOME/git/zmk -source $ZMK_DIR/.venv/bin/activate +ZMK_DIR="${HOME}/git/zmk" +MODULES_DIR="${HOME}/git/zmk_build/modules" +CONFIG_DIR="${HOME}/git/zmk_build/config" +BUILD_DIR="${HOME}/git/zmk_build" + +if [ ! -d "$ZMK_DIR" ]; then + printf "${RED}Error: ZMK directory not found at $ZMK_DIR${NORMAL}\n" + exit 1 +fi + +if [ ! -f "$ZMK_DIR/.venv/bin/activate" ]; then + printf "${RED}Error: Python virtual environment not found${NORMAL}\n" + exit 1 +fi + +source "$ZMK_DIR/.venv/bin/activate" build() { - printf "building ${GREEN}$1${NORMAL} for ${BLUE}$2${NORMAL}...\n" - (cd $ZMK_DIR/app - MODULE_CMD="" - if [ "$3" ]; then - MODULE_CMD="-DZMK_EXTRA_MODULES=$HOME/git/zmk_build/$3" + local shield=$1 + local board=$2 + local keyboard_module=$3 + + printf "building ${GREEN}${shield}${NORMAL} for ${BLUE}${board}${NORMAL}...\n" + + ( + cd "$ZMK_DIR/app" || exit 1 + + BASE_MODULES="" + if [ -d "$MODULES_DIR" ]; then + for module_dir in "$MODULES_DIR"/*; do + if [ -d "$module_dir" ]; then + if [ -z "$BASE_MODULES" ]; then + BASE_MODULES="$module_dir" + else + BASE_MODULES="$BASE_MODULES;$module_dir" + fi + fi + done fi - west build -p -b $2 -- -DSHIELD=$1 \ - -DZMK_CONFIG=$HOME/git/zmk_build/config $MODULE_CMD - cp build/zephyr/zmk.uf2 ~/$1.uf2 + + KEYBOARD_MODULE="" + if [ -n "$keyboard_module" ]; then + KEYBOARD_MODULE=";${BUILD_DIR}/${keyboard_module}" + fi + + west build -p -b "$board" -- -DSHIELD="$shield" \ + -DZMK_CONFIG="$CONFIG_DIR" \ + -DZMK_EXTRA_MODULES="${BASE_MODULES}${KEYBOARD_MODULE}" + + cp build/zephyr/zmk.uf2 "${HOME}/${shield}.uf2" ) + printf "${GREEN}complete${NORMAL}\n" } printf "${BOLD}firmware to build${NORMAL}...\n" printf "(1) flake\t(2) revxlp\t(3) settings reset:\t" -read opt; +read -r opt + case $opt in 1) build flake_dongle nice_nano "flake_dongle" @@ -38,8 +79,8 @@ case $opt in ;; 3) printf "${BOLD}select microcontroller${NORMAL}...\n" - printf "(1) nice nano v2\t(2) xiao ble:\t" - read val; + printf "(1) nice nano\t(2) xiao ble:\t" + read -r val case $val in 1) MCU="nice_nano" ;; 2) MCU="xiao_ble" ;; @@ -47,5 +88,8 @@ case $opt in esac build settings_reset $MCU ;; - *) printf "${RED}invalid entry${NORMAL}\n" ;; + *) + printf "${RED}invalid entry${NORMAL}\n" + exit 1 + ;; esac diff --git a/readme.md b/readme.md @@ -1,9 +1,10 @@ -### zmk build repository -my [zmk](https://zmk.dev) configuration & keyboard code +# zmk_build +This repository contains my [ZMK](https://github.com/zmkfirmware/zmk) keymap configuration & keyboard code. ![keyboard](https://i.imgur.com/bCRPsDy.jpg) -### misc -* [`util.h`](config/util.h) contains some simple c macros for combos, 3-key tap dance, & home-row mods. -* [`build.sh`](build.sh) is an interactive script to build and flash firmware using a local build environment. -* **layout** is near identical to my layout [here (keymapdb)](https://keymapdb.com/keymaps/waffle87), sans a couple things like unicode. +## Building +GitHub actions is used to build externally maintained keyboards (such as those that are modules, or live in upstream ZMK), and keyboards maintained within this repository can be built locally as modules. The ['build.sh'](build.sh) script simplifies running long `west` commands. + +## Layout & Features +The layout used across my ZMK keyboards matches near identically to that of my QMK keyboards, found [here](https://git.pngu.org/qmk_me/about/#layout). Urob's [zmk-helpers](https://github.com/urob/zmk-helpers) & [zmk-unicode](https://github.com/urob/zmk-unicode) modules are used to assist in configuring ZMK's Devicetree-oriented features.