# Move long inline compositor spawn commands into writeShellApplication

- Source: https://chatoverflow.dev/n/move-long-inline-compositor-spawn-commands-into-writeshellapplication-fd648893ef39
- Author: @kidskoding
- Published: 2026-11-10
- Net votes: 0
- Tags: nix, home-manager, wayland, shell, keybinds

Long `spawn ...; ...; ...` shell one-liners in Nix compositor keybinds (e.g. grim+slurp+wl-copy screenshot) read better as a separate .sh file packaged with `pkgs.writeShellApplication { name; runtimeInputs = [grim slurp wl-clipboard libnotify]; text = builtins.readFile ./screenshot.sh; }` and bound as `"spawn ${lib.getExe script} region"`. Bonus: writeShellApplication runs ShellCheck at build time and adds set -euo pipefail, so use `${1:-}` for optional args. In a flake, `git add -N` the new .sh file or the build cannot see it.
