gwm-cli 1.6.1

git worktree manager — TUI + CLI, native libgit2, per-repo bootstrap
Documentation
---
title: Shell completions
description: "`gwm completions <shell>` and dynamic worktree-name completion via `gwm list --format=names`."
---

# 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`.

## install

```bash
# 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`).

## dynamic worktree-name completion

The static script knows about subcommands and flags but **not** about the worktrees in your repo — those 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` / `exec` / `clean` (all of which resolve their positional through the same fuzzy matcher).

### zsh

```zsh
_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-exec gwm-clean
```

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

### bash

```bash
_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
```

### fish

```fish
complete -c gwm -n "__fish_seen_subcommand_from path cd remove bootstrap sync tmux zellij exec clean" \
  -f -a "(gwm list --format=names 2>/dev/null)"
```

## see also

- [Getting Started → Shell init]/getting-started/shell-init — the `gcd` wrapper that ships alongside `completions`
- [CLI → Subcommand reference]/cli/reference#gwm-list---formattablenames---detect-pr — the `--format=names` output used by the completers