apus completion

Generate shell completion scripts, cache them under Apus state, and optionally install them into your shell profile.

Usage

apus completion                          # print the detected shell's script
apus completion --shell fish             # print fish script
apus completion --write-state            # cache scripts for all shells
apus completion --write-state --install  # cache, then install in one step
apus completion --shell bash --write-state

Options

Install flow

--install points your profile at the cached script, so the cache must exist first. If the cache is missing, the command fails and tells you to run apus completion --write-state. Combine --write-state --install to do both in one step. Without --shell, the command preserves a recognized $SHELL. When $SHELL is missing or unrecognized, it defaults to PowerShell on Windows and zsh elsewhere.

The install writes a small # Apus Completion block into your shell profile and replaces any older slow source <(apus completion ...) lines with the cached source line:

Shell Profile
bash ~/.bashrc (falls back to ~/.bash_profile when ~/.bashrc is missing)
fish ~/.config/fish/config.fish
powershell ~/.config/powershell/Microsoft.PowerShell_profile.ps1 (on Windows: Documents/PowerShell/Microsoft.PowerShell_profile.ps1, or Documents/WindowsPowerShell/... for Windows PowerShell)
zsh $ZDOTDIR/.zshrc when ZDOTDIR is defined; otherwise ~/.zshrc (an empty ZDOTDIR resolves to /.zshrc)

Profile changes are staged beside the destination and atomically replace it only after a complete durable write. A failed install leaves an existing profile unchanged.

Installed source lines preserve literal cache paths, including spaces, quotes, dollar signs, and backslashes. Reinstalling replaces Apus's previous source line after the state directory changes.

A user-managed portable hook for the same cached script (for example [[ -f "${HOME}/.apus/completions/apus.bash" ]] && source "${HOME}/.apus/completions/apus.bash", as a dotfile manager would write) is recognized as completion being configured. Doctor and completion --install leave such managed lines byte-for-byte untouched instead of appending a duplicate literal-path block.

Permission failures

If Doctor or onboarding cannot update your shell profile, completion remains optional and setup continues. When a cache is available, the warning includes a command to load that cache in your current matching shell session. Run the complete command as printed. This does not install completion for future shell sessions.

For persistent installation, resolve the reported permission or read-only error before retrying apus completion --install. The failure location may be a staging directory or a symlink target, not the profile itself. Atomic replacement also needs write access to the destination directory. The installer uses the profile selected in the table above. It has no profile-file destination option.

Notes

Related