Files
container/docs/shell-completions.md
2026-08-11 09:34:53 -07:00

2.9 KiB
Raw Permalink Blame History

Shell completions

Generate and install completion scripts for zsh, bash, and fish.

Overview

The container --generate-completion-script [zsh|bash|fish] command generates completion scripts for the provided shell. Below is a detailed guide on how to install the completion scripts.

Note

See the swift-argument-parser documentation for more information about generating and installing shell completion scripts.

Installing zsh completions

If you have oh-my-zsh installed, you already have a directory of automatically loaded completion scripts — .oh-my-zsh/completions. Copy your new completion script to that directory. If the completions directory does not exist, simply make it.

mkdir -p ~/.oh-my-zsh/completions
container --generate-completion-script zsh > ~/.oh-my-zsh/completions/_container
source ~/.oh-my-zsh/completions/_container

Note

Your completion script must have the filename _container.

Without oh-my-zsh, youll need to add a path for completion scripts to your function path, and turn on completion script autoloading. First, add these lines to your ~/.zshrc file:

fpath=(~/.zsh/completion $fpath)
autoload -U compinit
compinit

Next, create a directory at ~/.zsh/completion and copy the completion script to the new directory.

mkdir -p ~/.zsh/completion
container --generate-completion-script zsh > ~/.zsh/completion/_container
source ~/.zshrc

Installing bash completions

If you have bash-completion installed, you can just copy your new completion script to the bash_completion.d directory.

Note

The path to the directory is dependent on how bash-completion was installed. Find the correct path and then copy the completion script there. For example, if you used homebrew to install bash-completion:

container --generate-completion-script bash > /opt/homebrew/etc/bash_completion.d/container
source /opt/homebrew/etc/bash_completion.d/container

Without bash-completion, youll need to source the completion script directly. Create and copy it to a directory such as ~/.bash_completions.

mkdir -p ~/.bash_completions
container --generate-completion-script bash >  ~/.bash_completions/container
source ~/.bash_completions/container

Furthermore, you can add the following line to ~/.bash_profile or ~/.bashrc, in order for every new bash session to have autocompletion ready.

source ~/.bash_completions/container

Installing fish completions

Copy the completion script to any path listed in the environment variable $fish_completion_path.

container --generate-completion-script fish > ~/.config/fish/completions/container.fish