run a command in the background from a keybinding without opening a pane
I would like a keybinding action that runs a command in the background, without
creating a pane. Today, the Run action always opens a new pane (tiled,
floating, or in place), and that pane takes focus. For commands that script
Zellij through zellij action ... that targeting at current focused pane, the newly opened pane is an annoying issue for the supposed workflow.
Motivation
Actions such as Write and WriteChars send fixed bytes to the focused pane.
That covers static input, but some bindings need input that is computed when the
key is pressed, such dynamic logic needs to be placed in a script.
And zellij action write-chars --pane-id ... already lets a script send the
result to a pane. The missing piece is a way to start such a script from a
keybinding without opening a pane.
Example: keyboard scrolling in fullscreen TUI apps
Some fullscreen TUI apps (for example, the Codex CLI) have no configurable
scroll keys. They scroll only with the mouse wheel or with PageUp/PageDown.
On macOS, PageUp/PageDown require Fn+Up/Fn+Down, and many external keyboards
have no Fn key. To scroll such apps from the keyboard, I bind a key that sends
mouse wheel events (SGR encoding, ESC [ < 64 ; COLUMN ; ROW M) to the focused
pane.
The bytes depend on runtime state, so they cannot be written in the config:
A script can compute all of this. The only way to start it from a keybinding is
Run:
bind "Ctrl u" {
Run "send-mouse-scroll" "--direction" "up" {
floating true
close_on_exit true
};
}This works, with two problems:
- Each key press briefly shows a floating pane.
- The new pane takes focus, so the script can no longer target "the focused
pane". It has to guess which pane had focus before, for example by selecting
the focused, non-floating pane in the same tab from
zellij action list-panes --json. The guess is wrong when the original pane was itself floating.
Proposal
Add a way for a keybinding to run a command without creating a pane. The
command should know which pane was focused when the key was pressed. For
example, Zellij could set ZELLIJ_PANE_ID to that pane, as proposed for run
commands in #4993.
Possible forms:
bind "Ctrl u" {
Run "send-mouse-scroll" "--direction" "up" {
background true
};
}Could this be a plugin?
Probably. But this means writing, compiling, and maintaining a Wasm plugin to get what is effectively a one-line shell call. A built-in action that runs a command given in its configuration, would make these bindings practical for users who are not plugin authors.
Related issues
- #4993: Make
$ZELLIJ_ORIGIN_PANE_IDavailable toruncommands. It covers the same need to know the origin pane from a command started by a keybinding. - #2222: (Re-)run a command in an existing pane with a keybinding.
Source: zellij-org/zellij