Add spawn-sh, spawn-at-startup-sh

Our top 10 most confusing config moments
This commit is contained in:
Ivan Molodetskikh
2025-08-20 14:31:34 +03:00
parent 1013147ba3
commit e81f356908
9 changed files with 125 additions and 9 deletions
+33 -1
View File
@@ -206,7 +206,8 @@ binds {
> }
> ```
Currently, niri *does not* use a shell to run commands, which means that you need to manually separate arguments.
For `spawn`, niri *does not* use a shell to run commands, which means that you need to manually separate arguments.
See [`spawn-sh`](#spawn-sh) below for an action that uses a shell.
```kdl
binds {
@@ -249,6 +250,37 @@ binds {
}
```
#### `spawn-sh`
<sup>Since: next release</sup>
Run a command through the shell.
The argument is a single string that is passed verbatim to `sh`.
You can use shell variables, pipelines, `~` expansion, and everything else as expected.
```kdl
binds {
// Works with spawn-sh: all arguments in the same string.
Mod+D { spawn-sh "alacritty -e /usr/bin/fish"; }
// Works with spawn-sh: shell variable ($MAIN_OUTPUT), ~ expansion.
Mod+T { spawn-sh "grim -o $MAIN_OUTPUT ~/screenshot.png"; }
// Works with spawn-sh: process substitution.
Mod+Q { spawn-sh "notify-send clipboard \"$(wl-paste)\""; }
// Works with spawn-sh: multiple commands.
Super+Alt+S { spawn-sh "pkill orca || exec orca"; }
}
```
`spawn-sh "some command"` is equivalent to `spawn "sh" "-c" "some command"`—it's just a less confusing shorthand.
Keep in mind that going through the shell incurs a tiny performance penalty compared to directly `spawn`ing some binary.
Using `sh` is hardcoded, consistent with other compositors.
If you want a different shell, write it out using `spawn`, e.g. `spawn "fish" "-c" "some fish command"`.
#### `quit`
Exit niri after showing a confirmation dialog to avoid accidentally triggering it.