Skip to content
gwmgwmgwmv1.10.0

Shell completions

gwm completions <shell> prints a static completion script (generated from the live clap argument tree, so it never drifts from the actual subcommands). Supported shells: zsh, bash, fish, powershell, elvish.

Terminal window
# zsh — drop into the first writable fpath entry
gwm completions zsh > "${fpath[1]}/_gwm"
# bash — system-wide
gwm completions bash | sudo tee /etc/bash_completion.d/gwm > /dev/null
# bash — per-user
gwm completions bash > ~/.local/share/bash-completion/completions/gwm
# fish
gwm completions fish > ~/.config/fish/completions/gwm.fish
# PowerShell — load into the current session (ephemeral)
gwm completions powershell | Out-String | Invoke-Expression
# PowerShell — persist by appending to $PROFILE
gwm completions powershell | Out-File -Append -Encoding utf8 $PROFILE
# elvish
gwm completions elvish > ~/.config/elvish/lib/gwm.elv

Open a fresh shell (or source your rc file) and tab completion is live for every subcommand, flag, and value-enum (e.g. gwm list --format=<TAB> offers table / names).

The static script knows about subcommands and flags but not about the worktrees in your repo, which change every time you run gwm create / remove. Wire a custom completer to gwm list --format=names for live completion of the worktree-name arg on path / cd / remove / bootstrap / sync / tmux / zellij / herdr / exec / clean (all of which resolve their positional through the same fuzzy matcher).

Terminal window
_gwm_worktrees() { compadd $(gwm list --format=names 2>/dev/null) }
compdef _gwm_worktrees gwm-path gwm-cd gwm-remove gwm-bootstrap gwm-sync gwm-tmux gwm-zellij gwm-herdr gwm-exec gwm-clean

(gwm-path, gwm-cd, etc. are the auto-generated function names the static _gwm completer registers per-subcommand.)

Terminal window
_gwm_worktrees() {
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "$(gwm list --format=names 2>/dev/null)" -- "$cur"))
}
complete -F _gwm_worktrees -o default gwm
Terminal window
complete -c gwm -n "__fish_seen_subcommand_from path cd remove bootstrap sync tmux zellij herdr exec clean" \
-f -a "(gwm list --format=names 2>/dev/null)"