> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/lucasgelfond/zerobrew/llms.txt
> Use this file to discover all available pages before exploring further.

# Shell Completion

> Enable tab completion for zerobrew commands in bash, zsh, and fish

zerobrew provides shell completion scripts that enable tab completion for commands, subcommands, and options in your shell.

## Supported Shells

Completion is available for:

* **bash**
* **zsh**
* **fish**
* **powershell** (Windows)
* **elvish**

## Installing Completion

Use the `zb completion` command to generate completion scripts for your shell.

### Bash

<Steps>
  <Step title="Generate completion script">
    ```bash theme={null}
    zb completion bash > ~/.local/share/bash-completion/completions/zb
    ```

    If the directory doesn't exist:

    ```bash theme={null}
    mkdir -p ~/.local/share/bash-completion/completions
    zb completion bash > ~/.local/share/bash-completion/completions/zb
    ```
  </Step>

  <Step title="Reload your shell">
    ```bash theme={null}
    source ~/.bashrc
    # or start a new terminal session
    ```
  </Step>

  <Step title="Test completion">
    ```bash theme={null}
    zb ins<TAB>        # Completes to: zb install
    zb install --<TAB> # Shows: --build-from-source --no-link
    ```
  </Step>
</Steps>

#### Alternative: Source directly in .bashrc

Add to your `~/.bashrc`:

```bash theme={null}
eval "$(zb completion bash)"
```

Then reload:

```bash theme={null}
source ~/.bashrc
```

### Zsh

<Steps>
  <Step title="Generate completion script">
    Create completions directory if needed:

    ```bash theme={null}
    mkdir -p ~/.zsh/completion
    ```

    Generate the script:

    ```bash theme={null}
    zb completion zsh > ~/.zsh/completion/_zb
    ```
  </Step>

  <Step title="Update .zshrc">
    Add the completion directory to your `fpath` before `compinit` in `~/.zshrc`:

    ```bash theme={null}
    # Add before compinit
    fpath=(~/.zsh/completion $fpath)
    autoload -Uz compinit
    compinit
    ```

    If you don't have `compinit` yet, add:

    ```bash theme={null}
    autoload -Uz compinit
    compinit
    ```
  </Step>

  <Step title="Reload your shell">
    ```bash theme={null}
    source ~/.zshrc
    # or
    exec zsh
    ```
  </Step>

  <Step title="Test completion">
    ```bash theme={null}
    zb bun<TAB>        # Completes to: zb bundle
    zb bundle <TAB>    # Shows: dump install
    ```
  </Step>
</Steps>

#### Alternative: Oh My Zsh users

If you use Oh My Zsh:

```bash theme={null}
zb completion zsh > ~/.oh-my-zsh/completions/_zb
```

Then reload:

```bash theme={null}
exec zsh
```

### Fish

<Steps>
  <Step title="Generate completion script">
    ```bash theme={null}
    zb completion fish > ~/.config/fish/completions/zb.fish
    ```

    Create the directory if needed:

    ```bash theme={null}
    mkdir -p ~/.config/fish/completions
    zb completion fish > ~/.config/fish/completions/zb.fish
    ```
  </Step>

  <Step title="Reload completions">
    Fish automatically loads completions from `~/.config/fish/completions/`. Start a new shell or run:

    ```bash theme={null}
    source ~/.config/fish/completions/zb.fish
    ```
  </Step>

  <Step title="Test completion">
    ```bash theme={null}
    zb mig<TAB>         # Completes to: zb migrate
    zb migrate --<TAB>  # Shows: --force --yes
    ```
  </Step>
</Steps>

### PowerShell (Windows)

Add to your PowerShell profile:

```powershell theme={null}
zb completion powershell | Out-String | Invoke-Expression
```

To find your profile location:

```powershell theme={null}
$PROFILE
```

### Elvish

Add to your `~/.elvish/rc.elv`:

```elvish theme={null}
eval (zb completion elvish)
```

## What Gets Completed

The completion scripts provide suggestions for:

### Commands

```bash theme={null}
zb <TAB>
```

Shows:

```
bundle      gc          info        list        reset
completion  help        init        migrate     run
install     outdated    uninstall   update
```

### Subcommands

```bash theme={null}
zb bundle <TAB>
```

Shows:

```
dump     install
```

### Flags and options

```bash theme={null}
zb install --<TAB>
```

Shows:

```
--build-from-source  -s    Build from source instead of bottle
--no-link                  Install without linking
```

```bash theme={null}
zb migrate --<TAB>
```

Shows:

```
--yes     -y    Skip confirmation prompts
--force         Force uninstall from Homebrew
```

### File paths

```bash theme={null}
zb bundle install --file <TAB>
```

Completes file paths in the current directory.

## Updating Completions

When you update zerobrew, regenerate completion scripts to get completions for new commands:

```bash theme={null}
# Bash
zb completion bash > ~/.local/share/bash-completion/completions/zb

# Zsh
zb completion zsh > ~/.zsh/completion/_zb

# Fish
zb completion fish > ~/.config/fish/completions/zb.fish
```

Then reload your shell.

## Troubleshooting

### Completions not working in bash

Ensure `bash-completion` is installed:

```bash theme={null}
# macOS
brew install bash-completion@2

# Ubuntu/Debian
sudo apt-get install bash-completion

# Fedora
sudo dnf install bash-completion
```

Then verify `~/.bashrc` sources it:

```bash theme={null}
# Add to ~/.bashrc if missing
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
```

### Completions not working in zsh

Verify `compinit` is being called:

```bash theme={null}
grep compinit ~/.zshrc
```

It should appear **after** your `fpath` modifications:

```bash theme={null}
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit
compinit
```

If you still have issues, rebuild the completion cache:

```bash theme={null}
rm ~/.zcompdump
exec zsh
```

### Completions not working in fish

Verify the file exists:

```bash theme={null}
ls ~/.config/fish/completions/zb.fish
```

Check for syntax errors:

```bash theme={null}
fish -n ~/.config/fish/completions/zb.fish
```

Reload fish config:

```bash theme={null}
source ~/.config/fish/config.fish
```

### Completion file permissions

Ensure completion files are readable:

```bash theme={null}
chmod 644 ~/.local/share/bash-completion/completions/zb
chmod 644 ~/.zsh/completion/_zb
chmod 644 ~/.config/fish/completions/zb.fish
```

## Manual Completion

If you prefer not to install completions permanently, you can source them temporarily:

```bash theme={null}
# Bash
source <(zb completion bash)

# Zsh
source <(zb completion zsh)

# Fish
zb completion fish | source
```

This enables completions for the current session only.

## Related Commands

* `zb --help` - View all available commands
* `zb <command> --help` - View help for a specific command
