Skip to main content
The completion command generates shell completion scripts for bash, fish, PowerShell, and zsh.

Usage

chezmoi completion <shell>

Description

Shell completion provides command-line suggestions and auto-completion for chezmoi commands, flags, and file paths. The completion command generates the appropriate completion script for your shell.

Supported Shells

  • bash - Bash completion
  • fish - Fish completion
  • powershell - PowerShell completion
  • zsh - Zsh completion

Examples

Bash

One-time setup:
# Generate and install completion
chezmoi completion bash > /etc/bash_completion.d/chezmoi

# Or for user-only installation
mkdir -p ~/.local/share/bash-completion/completions
chezmoi completion bash > ~/.local/share/bash-completion/completions/chezmoi
Add to .bashrc:
eval "$(chezmoi completion bash)"
Source immediately:
source <(chezmoi completion bash)

Zsh

One-time setup:
# Add to fpath
mkdir -p ~/.zsh/completion
chezmoi completion zsh > ~/.zsh/completion/_chezmoi

# Add to .zshrc (before compinit)
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit
Or generate on-the-fly: Add to .zshrc:
eval "$(chezmoi completion zsh)"
For Oh My Zsh:
mkdir -p ~/.oh-my-zsh/custom/plugins/chezmoi
chezmoi completion zsh > ~/.oh-my-zsh/custom/plugins/chezmoi/_chezmoi

# Add 'chezmoi' to plugins in .zshrc
plugins=(git ... chezmoi)

Fish

One-time setup:
chezmoi completion fish > ~/.config/fish/completions/chezmoi.fish
Source immediately:
chezmoi completion fish | source

PowerShell

Add to profile:
chdir completion powershell >> $PROFILE
Or load dynamically:
chezmoi completion powershell | Out-String | Invoke-Expression

Platform-Specific Instructions

macOS

Bash (via Homebrew):
# Install bash-completion if not already installed
brew install bash-completion

# Generate completion
chezmoi completion bash > $(brew --prefix)/etc/bash_completion.d/chezmoi
Zsh (default shell on macOS Catalina+):
mkdir -p ~/.zsh/completion
chezmoi completion zsh > ~/.zsh/completion/_chezmoi

# Add to ~/.zshrc
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit

Linux

Debian/Ubuntu (bash):
sudo chezmoi completion bash > /etc/bash_completion.d/chezmoi
Fedora/RHEL/CentOS (bash):
sudo chezmoi completion bash > /etc/bash_completion.d/chezmoi
Arch Linux (zsh):
sudo chezmoi completion zsh > /usr/share/zsh/site-functions/_chezmoi

Windows

PowerShell:
# Create profile if it doesn't exist
if (!(Test-Path -Path $PROFILE)) {
    New-Item -ItemType File -Path $PROFILE -Force
}

# Add completion
chezmoi completion powershell >> $PROFILE

Testing Completion

After installation, test the completion:
# Type 'chezmoi ' and press Tab
chezmoi <Tab>

# Should show available commands:
apply  add  edit  init  update  status  diff  ...

# Test flag completion
chezmoi apply --<Tab>

# Should show available flags:
--apply  --dry-run  --exclude  --include  --verbose  ...

Features

Command completion

chezmoi <Tab>
# Shows: add, apply, cd, diff, edit, init, status, update, ...

Flag completion

chezmoi apply --<Tab>  
# Shows: --dry-run, --exclude, --include, --recursive, --verbose, ...

File path completion

chezmoi add ~/<Tab>
# Shows files in your home directory

chezmoi edit ~/.<Tab>
# Shows dotfiles in your home directory

Subcommand completion

chezmoi git <Tab>
# Shows: add, commit, push, pull, status, ...

Troubleshooting

Completion not working (bash)

Ensure bash-completion is installed:
# Debian/Ubuntu
sudo apt install bash-completion

# macOS
brew install bash-completion

# Fedora
sudo dnf install bash-completion
Source completion manually:
source /etc/bash_completion

Completion not working (zsh)

Ensure compinit is loaded:
# Add to .zshrc before loading completion
autoload -Uz compinit && compinit
Check fpath:
echo $fpath
# Should include the directory containing _chezmoi

Completion not working (fish)

Check completion file location:
echo $fish_complete_path
# Should include ~/.config/fish/completions
Regenerate completions:
rm ~/.config/fish/completions/chezmoi.fish
chezmoi completion fish > ~/.config/fish/completions/chezmoi.fish

Permission denied

If installing system-wide:
sudo chezmoi completion bash > /etc/bash_completion.d/chezmoi
Or install to user directory instead.

Updating Completions

After upgrading chezmoi, regenerate completions:
# Bash
chezmoi completion bash > ~/.local/share/bash-completion/completions/chezmoi

# Zsh  
chezmoi completion zsh > ~/.zsh/completion/_chezmoi

# Fish
chezmoi completion fish > ~/.config/fish/completions/chezmoi.fish
  • init - Initialize chezmoi

Build docs developers (and LLMs) love