Skip to content
hamidzrPublic

About

dmenu alternative for macOS: a fast native fuzzy menu written in Zig against AppKit

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

zmenu

zmenu is a fast, native dmenu alternative for macOS: a fuzzy menu in the spirit of dmenu, rofi and choose. Pipe a list into it, pick an item in a popup search window, and the choice comes back on stdout. It is written in Zig against AppKit, starts in tens of milliseconds, and also takes live item updates over a local socket.

zmenu window with fuzzy-matched rows, icons, subtitles and an action footer

Product page: zmenu on Latent Byte. zmenu replaces gmenu, the earlier Go version, and reads the same GMENU_* settings and config files.

Install

With Homebrew (builds from source, needs the Xcode Command Line Tools):

brew install latentbyte/tap/zmenu

From a checkout, with Zig 0.17 and just:

git clone https://github.com/hamidzr/zmenu
cd zmenu
just install                    # optimized build of zmenu and zmenuctl into ~/.local/bin

Make sure ~/.local/bin is on your PATH. Without just, run zig build -Doptimize=ReleaseFast --prefix ~/.local.

Quick start

printf "alpha\nbravo\ncharlie\n" | zmenu                         # prints the picked line
git branch --format='%(refname:short)' | zmenu | xargs git switch  # branch switcher
open -a "$(ls /Applications | sed 's/\.app$//' | zmenu)"          # app launcher

Exit codes tell a script what happened: 0 when an item was accepted, 2 when the user pressed Esc or clicked away, 1 on errors such as empty stdin. Bind any of these to a hotkey (skhd, Hammerspoon, Raycast script, BetterTouchTool) for a keyboard launcher.

What it does

  • Reads menu items from stdin (one per line). If stdin is empty, it exits with a non-zero code.
  • Opens a native window with a search field and a list of items.
  • Typing filters the list with a tokenized, case- and accent-insensitive fuzzy match (cafe finds Café; results capped at 10). Ranking prefers an exact label, then a label prefix, then word-start matches and acronyms (vsc finds Visual Studio Code), then scattered letters; ties keep the order the client sent. If there are no matches, it falls back to Levenshtein distance suggestions unless disabled.
  • Enter prints the selected (default top) item to stdout and exits 0; Esc clears a non-empty query; Esc on an empty query cancels with a non-zero exit code. Enter with no matches does nothing in --ipc-only (the menu stays open).
  • While a streaming source (--ipc-only, --follow-stdin) has sent nothing yet the list shows a dim "Loading..." line; a query with no matches shows "No results". Neither is a row, so nothing is selectable, counted or acceptable.
  • Matched characters in each row are drawn bold and accent-tinted (bold only on the selected row); matching text is found with the same rules as ranking.
  • Up/Down/Tab/Shift+Tab, Ctrl+N/P and Ctrl+J/K move the selection (wrapping). PageUp/PageDown move a page; Cmd+Up/Cmd+Down jump to the first/last item; Home/End do the same while the query is empty.
  • Clicking a row accepts that item; the search field keeps keyboard focus.
  • Cmd+1 to Cmd+9 accept the corresponding item; the first nine rows show a dim command-key hint (the command symbol plus the digit). numeric_selection_mode: off turns them off and removes the column.
  • Ctrl+L clears the query.
  • IPC items can declare action (plain Enter label), actions (alternates with mods, such as Cmd+Enter) and confirm. Cmd/Alt/Shift/Ctrl+Enter accepts only when the selected item has an action with exactly those modifiers (otherwise a beep) and the output gains mods. A footer bar lists the Enter action, up to two alternates and Cmd+K Actions. Cmd+K opens an action panel for the selected item (Enter runs the chosen row, Esc or Cmd+K goes back). confirm needs a second Enter within 4 seconds, with the prompt shown in the row.
  • A pid file in the temp dir prevents multiple instances per menu id.
  • When menu_id is set, the last query + selection are stored under ~/.cache/gmenu/<menu_id>/cache.yaml. Cache dir is created 0700 and cache.yaml / pid files 0600.

Run from a checkout

Provide stdin, then launch the app:

printf "alpha\nbravo\ncharlie\n" | zig build run

If you run without stdin, zmenu exits with an error.

Config + CLI

Supported flags: --menu-id/-m, --initial-query/-q, --search-method/-s, --preserve-order/-o, --no-levenshtein-fallback, --auto-accept, --terminal, --follow-stdin, --ipc-only, --numeric-selection-mode, --no-numeric-selection, --show-icons, --title/-t, --prompt/-p, --min-width, --min-height, --max-width, --max-height, --row-height, --field-height, --padding, --numeric-column-width, --icon-column-width, --alternate-rows, --background-color, --list-background-color, --field-background-color, --text-color, --secondary-text-color, --selection-color, --corner-radius, --no-vibrancy, --vibrancy=, --init-config, --render-bench, --startup-profile. Environment overrides are listed under Environment variables. Rounded corners (14pt) and a translucent adaptive (popover) vibrancy material are on by default; disable with --no-vibrancy or set corner_radius/vibrancy in the config file. Theme colors accept hex strings like #RRGGBB or #RRGGBBAA. Empty/none/default (the default for every color) uses dynamic system colors: the selection follows the accent color, text follows Light/Dark mode, and the window switches with the system appearance. Size tuning is available via field_height, padding, and the column width settings. --auto-accept fires immediately in classic mode, waits for stdin EOF in --follow-stdin, and stays disabled in --ipc-only because that stream never naturally closes.

Environment variables

Settings precedence is CLI flags > GMENU_* env > config file > defaults. Read in src/cli/env.zig; defaults come from src/config.zig. Invalid values abort startup. Booleans accept true/false, 1/0, yes/no, on/off (case-insensitive). Colors accept #RRGGBB or #RRGGBBAA; empty, none, or default clears the color to the system default. Sizes are floating-point points.

Variable Meaning Default
GMENU_TITLE Window title gmenu
GMENU_PROMPT Search field placeholder (terminal mode prompt) Search
GMENU_MENU_ID Menu ID (letters, digits, -, _, .; max 64; no leading dot) for cache, PID lock, and IPC socket names. Applied after config load, so only --menu-id selects the scoped config file empty
GMENU_INITIAL_QUERY Prefilled query empty (cached last query when a menu ID is set)
GMENU_TERMINAL_MODE Use terminal mode instead of the GUI false
GMENU_FOLLOW_STDIN Keep reading stdin and stream new items false
GMENU_IPC_ONLY Ignore stdin; take items over IPC and print the JSON item on accept false
GMENU_UNIQUE Drop items with duplicate labels (stdin and IPC updates) false
GMENU_MIN_WIDTH Initial window width, capped by max width 800
GMENU_MIN_HEIGHT Initial window height, capped by max height and snapped to whole rows 450
GMENU_MAX_WIDTH Max window width (0 disables the cap) 1920
GMENU_MAX_HEIGHT Max window height (0 disables the cap) 1080
GMENU_ROW_HEIGHT Result row height 34
GMENU_FIELD_HEIGHT Search field height 44
GMENU_PADDING Window padding 14
GMENU_NUMERIC_COLUMN_WIDTH Numeric shortcut column width 30
GMENU_ICON_COLUMN_WIDTH Icon column width 46
GMENU_ALTERNATE_ROWS Alternating row backgrounds false
GMENU_CORNER_RADIUS Window corner radius 14
GMENU_VIBRANCY Translucent hudWindow vibrancy background true
GMENU_BACKGROUND_COLOR Window background color dark (rgba 0.06, 0.07, 0.09, 0.98)
GMENU_LIST_BACKGROUND_COLOR Result list background color dark (rgba 0.06, 0.07, 0.09, 0.98)
GMENU_FIELD_BACKGROUND_COLOR Search field background color rgba 0.12, 0.13, 0.17, 1.0
GMENU_TEXT_COLOR Primary text color rgba 0.94, 0.95, 0.97, 1.0
GMENU_SECONDARY_TEXT_COLOR Secondary text color rgba 0.75, 0.77, 0.82, 1.0
GMENU_SELECTION_COLOR Selected row highlight accent blue (rgba 0.21, 0.38, 0.78, 0.95)
GMENU_SEARCH_METHOD direct, fuzzy, fuzzy1, fuzzy3, or default (= fuzzy) fuzzy
GMENU_PRESERVE_ORDER Keep input order instead of sorting matches by score false
GMENU_LEVENSHTEIN_FALLBACK Add edit-distance matches when fewer than 3 results match true
GMENU_AUTO_ACCEPT Accept a single item automatically (see --auto-accept notes above) false
GMENU_ACCEPT_CUSTOM_SELECTION Enter with no matches prints the typed query (not in --ipc-only) true
GMENU_NUMERIC_SELECTION_MODE on, off, or auto (shortcuts only when at most 9 items match) auto
GMENU_NO_NUMERIC_SELECTION Legacy alias: true sets mode off, false sets on; GMENU_NUMERIC_SELECTION_MODE wins if both are set unset
GMENU_SHOW_ICONS Show the item icon column false

IPC + dynamic items

zmenu listens on a local Unix socket for dynamic item updates. Protocol v2 accepts an optional absolute file or app bundle path in icon; --show-icons enables its workspace icon column. Use zmenuctl to send set, append, or prepend commands to a running instance:

printf "alpha\nbravo\n" | zmenuctl --menu-id demo set --stdin
zmenuctl --menu-id demo append "charlie"
echo '{"v":3,"cmd":"set","items":[{"id":"a","label":"A"}]}' | zmenuctl --menu-id demo --json

--json reads one raw protocol message from stdin, checks that it parses, and sends it unchanged.

zmenu --version prints zmenu and a line ipc-protocol 3, the IPC protocol version this build speaks (a client such as combo-switcher doctor can check compatibility). It exits before any AppKit setup.

Protocol v3 adds optional subtitle, detail and keywords text, kinds with search scopes, calc, prefix and fallback template rows, and a loading flag; see IPC_PROTOCOL.md.

IPC-only selection mode ignores stdin and prints the full JSON item on accept:

zmenu --menu-id demo --ipc-only

Example stdout:

{"id":"window:123","label":"Safari — Docs","icon":"/Applications/Safari.app"}

Compatibility notes

  • Search methods supported: direct, fuzzy, fuzzy1, fuzzy3, default (default matches fuzzy). Regex or exact modes are not implemented.
  • The config filename is config.yaml in the standard gmenu config locations; gmenu.yaml is not read.
  • Default window bounds are 800x450 with max 1920x1080 (override via config/env/flags).
  • Default row height is 34, field height 44, icon column 46, numeric column 40; tune via row_height, field_height, icon_column_width, and numeric_column_width.
  • Default selection_color is an accent blue that stays visible under vibrancy; set it to an empty string to fall back to the system selection highlight.

Migration from Go gmenu

  • Copy your existing config.yaml into the same gmenu config locations; ensure search_method is one of the supported values above.
  • If you previously used exact or regex, switch to direct or fuzzy since zmenu does not implement regex search.
  • Numeric selection defaults to numeric_selection_mode: auto. In the GUI it always shows Cmd+1..9 hints on the first nine rows; in terminal mode (plain digits) it enables them only when results are <= 9 and the query does not end in a digit.
  • Set numeric_selection_mode: on to always enable numeric shortcuts, or off to always disable them.
  • no_numeric_selection and GMENU_NO_NUMERIC_SELECTION are still supported as legacy on/off aliases.
  • Terminal mode is intentionally minimal and chooses the first match on Enter.

Development

just check runs formatting checks and tests, just snapshot renders the UI offscreen to zig-out/snapshots/ without taking focus.

Visual regression

just visual captures a snapshot of the UI using scripts/visual_test.sh. The first run writes samples/visual_baseline.png; set UPDATE_SNAPSHOT=1 to refresh the baseline. The script relies on macOS Accessibility + Screen Recording permissions to capture the window.

Spawn benchmark

just bench (or scripts/bench_spawn.sh) measures cold spawn-to-accept latency with hyperfine. It feeds a single item so --auto-accept fires without user interaction. Note this exits before app.run(), so it is a process-init/filter floor, not paint-to-visible.

Render benchmark

just render-bench (or scripts/render_bench.sh, COUNT=2000 by default) measures table reload + paint cost. It runs zmenu --render-bench, which shows the window, types the first item's label one character at a time (filter + reload + paint per keystroke), accepts the item, and exits. It prints per-keystroke stats plus spawn-to-window time, and times the whole flow with hyperfine when available. The table is view-based (tableView:viewForTableColumn:row: and a custom NSTableRowView), so selection_color draws the row highlight.

Startup keyboard benchmark

just startup-bench (or scripts/startup_bench.sh) sends real keyboard events at fixed offsets from process launch and checks the complete query. An owned test window catches early keys. Requires existing macOS Accessibility and event-posting permissions. Use --binary "$(command -v zmenu)" --ready --accept --profile to test the installed executable, or --mode ipc --ipc-items to include dynamic item delivery through zmenuctl. zmenu --startup-profile logs timestamp-only startup stages to stderr, including the first accepted text change. See startup measurements and limits.

Support

zmenu is free. If it saves you time, you can support us with a tip.

License

MIT

About

dmenu alternative for macOS: a fast native fuzzy menu written in Zig against AppKit

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages