pkg-completion(1)
NAME
pkg-completion - print a shell completion script
SYNOPSIS
pkg completion shell
DESCRIPTION
Prints a tab-completion script for shell on standard output. It doesn't install anything. Redirect it to wherever your shell looks for completions.
shell is one of bash, zsh, fish, elvish or powershell.
Do I need this?
On Ur, usually not. The pkg package already ships the bash, zsh and fish scripts, generated by this very command when it was built:
/usr/share/bash-completion/completions/pkg /usr/share/zsh/site-functions/_pkg /usr/share/fish/vendor_completions.d/pkg.fish
Those are package files. Don't overwrite them by hand, because pkg-verify(1) will rightly call that drift, and the next upgrade of pkg puts them back. Reach for this command for a shell the package doesn't cover, for a per-user setup, for a pkg you built yourself, or when you're packaging it.
What does it complete?
Subcommands, their aliases, and flags. The script is generated from the command's own definition, so it always matches the binary that printed it.
It doesn't complete package names. That would mean querying the repository chain on every keystroke, and nobody wants their tab key to wait on the network.
OPTIONS
No options of its own.
EXAMPLES
bash, for one user
mkdir -p ~/.local/share/bash-completion/completions pkg completion bash > ~/.local/share/bash-completion/completions/pkg
bash, in the current shell only
source <(pkg completion bash)
zsh, for one user
mkdir -p ~/.zfunc pkg completion zsh > ~/.zfunc/_pkg
Then put fpath=(~/.zfunc $fpath) before compinit in ~/.zshrc.
fish, for one user
pkg completion fish > ~/.config/fish/completions/pkg.fish
elvish
pkg completion elvish > ~/.config/elvish/lib/pkg.elv
After upgrading pkg
A per-user script doesn't follow the package, so regenerate it:
pkg upgrade pkg pkg completion bash > ~/.local/share/bash-completion/completions/pkg
Checking what was generated
pkg completion bash | head -20 pkg completion bash | wc -l
In a package recipe or an image bake
Run the binary you just built, so the script matches it:
install -d "$DESTDIR/usr/share/bash-completion/completions" "$DESTDIR/usr/bin/pkg" completion bash \
"$DESTDIR/usr/share/bash-completion/completions/pkg" install -d "$DESTDIR/usr/share/zsh/site-functions" "$DESTDIR/usr/bin/pkg" completion zsh \ "$DESTDIR/usr/share/zsh/site-functions/_pkg"
EXIT STATUS
0 on success. 2 when shell isn't one of the supported values; that's a usage error, and it lists the values that are.