Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Launcher

Grows the island into a search box. Your most used apps come first; typing searches names, descriptions and keywords, and app actions like Firefox’s “New Private Window” when you search for them. Enter or a click picks a result, Escape or a click elsewhere closes the launcher.

Apps and commands start through uwsm app in a uwsm session, otherwise through systemd-run, so they never belong to mochid.

Each result takes two lines by default: its name, and its description under it. With layout = "compact", each takes one line, the icon and the name, and nine fit where seven did; only the selected result shows its description, at the end of its line.

Providers

Results come from providers. These are built in:

ProviderPrefixAnswers
appsnoneYour apps and their actions
windowsnoneOpen windows on every workspace whose title or app has every word you typed, the one focused last first, above the apps. Enter focuses one and switches to its workspace. Needs wlr-foreign-toplevel-management, which Hyprland, Sway and niri have
calculator=Math, like =2^10 or =sqrt(2)*pi. Plain math like 2+2 works without the prefix, above the apps. Enter copies the result
commands>A shell command, like > htop, with the ones you ran before. Enter runs it, Shift+Enter runs it in the terminal from terminal
files/Files and folders in your home by name, from an index in memory. Enter opens one, Shift+Enter or the folder button shows it selected in your file manager, and dragging one drops it on another app
web searches!w, !g, !gh, !yt, !nix, !wiki!w rust opens a DuckDuckGo search for “rust”; the others search Google, GitHub, YouTube, NixOS packages and Wikipedia. engines adds more
emoji:Emoji by name. Enter types it into the window you were in, Shift+Enter copies it
colors#A color you type, in every format, or a pick from the screen
timer:t A timer of the length you type, like :t 10m Pizza, the running timers to pause, and the stopwatch with :t sw

The emoji, colors and timer providers come from their modules, so they’re there when those modules run.

A query that starts with a provider’s prefix asks only that provider, with the rest of the query. Providers without a prefix answer every query, and their results show together under headings, in the providers’ order. The built-ins and modules answer at once; scripts a moment after you stop typing, and their results come in as they’re ready.

mochi ipc launcher open : opens the launcher with : typed, so a key can go straight to a provider.

The file index covers your home folder without hidden files and folders and build folders like node_modules and target, up to 200 000 entries. It’s built in the background the first time a search asks for files after you open the launcher, when there’s none or it’s more than 15 seconds old, so opening the launcher for apps never reads your home folder. Nothing runs in between. While it builds, the search field says “Indexing”, and a / search shows its files once it’s done.

With watch = true in [module.launcher.files], the index is built when Mochi starts and follows your files through inotify: a file or folder you make, delete, rename or move shows up in the results, or leaves them, right away, even with the launcher open. Every indexed folder takes one inotify watch, and every change in them wakes Mochi, which a busy home folder, like one with game installs or builds, makes costly. When the system runs out of watches (the fs.inotify.max_user_watches sysctl, 8192 on older kernels), mochid logs it once and goes back to building the index when a search asks for files.

The calculator knows + - * / % ^, parentheses, !, pi, e, tau, and the functions sqrt cbrt abs floor ceil round sin cos tan asin acos atan sinh cosh tanh ln log log2 exp min max pow, with trig in radians. A number before a name or a parenthesis multiplies, so 2pi works.

Script providers

A section with a command adds a provider of your own. The launcher runs the command with the query as its last argument, and in MOCHI_QUERY, and reads one result per line of what it prints:

{"title": "Search the web for rust", "subtitle": "https://duckduckgo.com/?q=rust", "icon": "web-browser", "open": "https://duckduckgo.com/?q=rust"}
Key
titleRequired
subtitleA second line
iconAn icon theme name, or a file path
glyphA short text shown big in place of the icon, like an emoji
colorA CSS color, shown as a round swatch in place of the icon
copyEnter copies this text, through the clipboard module, or wl-copy without it
typeEnter pastes this text into the window you were in, through the clipboard module
openEnter opens this URL or file with xdg-open
runEnter runs this shell command, Shift+Enter in a terminal
altWhat Shift+Enter does, as an object with one of the four: {"copy": "😀"}. A run result runs in a terminal on Shift+Enter without one
idPassed to the provider’s pick command after Enter
fileA file or folder the result is: it drags out onto other apps, and Shift+Enter, without an alt, and the folder button show it in the file manager

A result has at most one of copy, type, open and run. A newer query stops a script that hasn’t finished, and so does timeout_ms, 2 seconds by default. A script without a prefix isn’t asked for an empty query.

Two example scripts are in the repository’s examples/launcher, and the test suite runs both. The launcher has both built in now, faster, so they’re here to copy from. Web search:

#!/bin/sh
# A launcher provider: searches the web for what you type. In config.toml:
#
#   [module.launcher.providers.web]
#   prefix = "!w"
#   title = "Web"
#   command = ["sh", "/path/to/web-search.sh"]
#
# The launcher runs it with the query as its last argument and reads one
# JSON result per line. Set SEARCH_URL to use another engine; the query
# goes at its end.

query=$1
[ -n "$query" ] || exit 0
engine=${SEARCH_URL:-https://duckduckgo.com/?q=}

# Every byte but letters, digits and -._~ becomes %XX.
encode() {
    printf '%s' "$1" | od -An -v -tx1 | tr -s ' \n' '  ' | {
        read -r bytes
        for byte in $bytes; do
            case $byte in
            3[0-9] | 4[1-9a-f] | 5[0-9a] | 6[1-9a-f] | 7[0-9a] | 2d | 2e | 5f | 7e)
                printf "\\$(printf '%03o' "0x$byte")" ;;
            *) printf '%%%s' "$(printf '%s' "$byte" | tr 'a-f' 'A-F')" ;;
            esac
        done
    }
}

# A JSON string's inside: backslashes and quotes escaped.
json() {
    printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}

url=$engine$(encode "$query")
printf '{"title": "Search the web for %s", "subtitle": "%s", "icon": "web-browser", "open": "%s"}\n' \
    "$(json "$query")" "$(json "$url")" "$(json "$url")"

Files and folders in your home, through fd when installed:

#!/bin/sh
# A launcher provider: finds files and folders in your home by name, and
# opens the one you pick. In config.toml:
#
#   [module.launcher.providers.files]
#   prefix = "/"
#   title = "Files"
#   command = ["sh", "/path/to/files.sh"]
#
# It uses fd when installed, find otherwise, and skips hidden files. Set
# FILES_ROOT to search somewhere else than your home.

query=$1
[ -n "$query" ] || exit 0
root=${FILES_ROOT:-$HOME}

json() {
    printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
}

if command -v fd >/dev/null 2>&1; then
    fd --max-results 30 --fixed-strings --ignore-case -- "$query" "$root"
else
    find "$root" -name '.*' -prune -o -iname "*$query*" -print 2>/dev/null | head -n 30
fi | while IFS= read -r path; do
    path=${path%/}
    [ "$path" = "$root" ] && continue
    if [ -d "$path" ]; then icon=folder; else icon=text-x-generic; fi
    printf '{"title": "%s", "subtitle": "%s", "icon": "%s", "open": "%s"}\n' \
        "$(json "${path##*/}")" "$(json "${path%/*}")" "$icon" "$(json "$path")"
done

Plugins can offer providers too, with results from their backend: see Launcher providers. The example emoji picker in examples/plugins/emoji is one, with ;.

# Launcher: `mochi ipc launcher toggle` searches your apps. Bind it to a key.
[module.launcher]
# The terminal that runs terminal apps when uwsm doesn't. None picks
# xdg-terminal-exec when it's installed, otherwise the one $TERMINAL names.
# terminal = []
# The most results to list.
# max_results = 50
# How results are listed: Comfortable, two lines each, the name and its
# description, or Compact, one line each, with the description only on the
# selected one.
# layout = "comfortable"

# Providers: where results come from. The built-ins are "apps", "calculator"
# (prefix "=", and plain math like 2+2 without it), "commands" (prefix ">";
# Shift+Enter runs one in a terminal), "files" (prefix "/"; Shift+Enter opens
# the folder) and the web searches below. Modules offer more: emoji with ":"
# and colors with "#". A
# [module.launcher.providers.<name>] section changes one, with any of:
#
#   enabled = false     # turn it off
#   prefix = "c"        # what a query starts with to ask only it; "" for none
#   order = 5           # lower shows first; apps are at 0
#   title = "Maths"     # the heading over its results
#
# A section with a command adds a script provider. It runs with the query
# as its last argument, and prints one JSON result per line, like
#   {"title": "Rust", "subtitle": "rust-lang.org", "open": "https://rust-lang.org"}
# with at most one of copy, type, open or run for what Enter does:
#
#   [module.launcher.providers.web]
#   prefix = "!w"
#   command = ["sh", "/path/to/web-search.sh"]
#   timeout_ms = 2000   # stopped after this long
#   pick = ["my-script", "--picked"]  # run with a result's "id" once picked

# Web searches, by the word after "!": "!w rust" searches DuckDuckGo. Built
# in are w (DuckDuckGo), g (Google), gh (GitHub), yt (YouTube), nix (NixOS
# packages) and wiki (Wikipedia). A section adds one, or changes or removes
# a built-in one with an empty url; %s is where the query goes:
#
#   [module.launcher.engines.crates]
#   title = "crates.io"
#   url = "https://crates.io/search?q=%s"

# The files provider searches an index of your home folder, built in the
# background the first time a search asks for files each time the launcher
# opens, when the index is gone or 15 seconds old; the search field says "Indexing" meanwhile. With
# `watch = true` it's built when Mochi starts and kept up to date through
# inotify, one watch per folder, which costs memory and wakes Mochi on every
# change in them; without enough watches (fs.inotify.max_user_watches), it
# falls back to building on open.
# Hidden files and folders are left out, and these:
#
#   [module.launcher.files]
#   roots = ["~"]
#   ignore = ["node_modules", "target", "__pycache__", "venv", "result", "dist", "build"]
#   max = 200000
#   watch = false
ActionWhat it does
toggle, open, closeShows or hides the launcher
launch <id>Starts an app by desktop id, like firefox.desktop

The launcher sends search and activate itself.