Skip to content

Shell Completions

Polytoken generates completion scripts for bash, zsh, fish, PowerShell, and Elvish. The completions command writes the script to stdout. Redirect the output to the location your shell expects.

Terminal window
polytoken completions bash

Replace bash with zsh, fish, powershell, or elvish for the corresponding shell.

The commands below write the completion script to the default location for each shell. For bash, fish, and Elvish, the install location sits under an $XDG_* directory: bash under $XDG_DATA_HOME (default: ~/.local/share), fish and Elvish under $XDG_CONFIG_HOME (default: ~/.config). Substitute your configured directory in those commands if you have set either variable. The zsh and PowerShell locations follow shell conventions rather than $XDG_*.

Polytoken’s bash script needs nothing besides Bash itself and the polytoken binary, so it runs without the bash-completion package. With bash-completion installed, Bash loads the completion file on demand the first time you complete a polytoken command, which is why the install command below writes to that directory. Without bash-completion, source the file from your Bash startup files instead.

Terminal window
mkdir -p ~/.local/share/bash-completion/completions
polytoken completions bash > ~/.local/share/bash-completion/completions/polytoken

Restart your shell to activate completions, or run source ~/.local/share/bash-completion/completions/polytoken to activate them in the current session.

The directory containing the completion file must be on your fpath before compinit runs. Add this to your ~/.zshrc if it is not already present:

Terminal window
fpath+=~/.zfunc

Then generate the completion:

Terminal window
mkdir -p ~/.zfunc
polytoken completions zsh > ~/.zfunc/_polytoken

Restart your shell or run autoload -Uz compinit && compinit to activate completions.

Terminal window
mkdir -p ~/.config/fish/completions
polytoken completions fish > ~/.config/fish/completions/polytoken.fish

Fish loads completions automatically. Restart your shell to activate completions.

Append to your PowerShell profile rather than overwriting it:

Terminal window
polytoken completions powershell | Add-Content -Path $PROFILE

Reload the profile to activate completions:

Terminal window
. $PROFILE
Terminal window
mkdir -p ~/.config/elvish/lib
polytoken completions elvish > ~/.config/elvish/lib/polytoken.elv

Restart your shell or run use polytoken to activate completions.

For polytoken new --model <TAB>, polytoken new --model=<TAB>, and the same positions on polytoken exec, completions come from the effective runtime model catalog, never from files in your working directory. The candidate list covers every configured model plus its selectable references: reasoning effort suffixes like model(high), the reasoning-off form model(none) where the model allows disabling reasoning, and the thinking form model(t) for models that support thinking. The lookup runs polytoken print models at TAB time, so the candidate list includes dynamic provider catalogs. When the lookup cannot resolve a dynamic catalog, it skips that catalog and offers the models written in your config files.

Model completion behaves the same in all five shells. Each shell’s completion script suppresses lookup errors and returns zero candidates when no configuration exists or configuration loading fails, so you get an empty model list, never files.

If your invocation carries a root --config-dir <dir> (or --config-dir=<dir>) before the subcommand, every shell forwards it to the lookup, so the offered models match the config your command will actually use. The completion scripts do not forward a root --working-dir. Without an explicit --config-dir, the lookup reads project config from the directory your shell is in, which can differ from the directory the command will run in.

The completions command requires no configuration and works immediately after installation, before any provider or config setup. It never opens the first-run configurator, and stdout carries only the completion script. The --model value lookup skips the configurator too; with no config in place it offers zero candidates.