Using shell completion scripts
Customize your shell to automatically complete swift package commands.
Overview
Package manager ships with completion scripts for Bash, Zsh, and Fish. Generate completion lists for your shell in order to use it.
Bash
Use the following commands to install the Bash completions to ~/.swift-package-complete.bash and automatically load them using your ~/.bash_profile file.
swift package completion-tool generate-bash-script > ~/.swift-package-complete.bash
echo -e "source ~/.swift-package-complete.bash\n" >> ~/.bash_profile
source ~/.swift-package-complete.bashAlternatively, add the following commands to your ~/.bash_profile file to directly load completions:
# Source Swift completion
if [ -n "`which swift`" ]; then
eval "`swift package completion-tool generate-bash-script`"
fiZsh
Use the following commands to install the Zsh completions to ~/.zsh/_swift. You can chose a different folder, but the filename should be _swift. This will also add ~/.zsh to your $fpath using your ~/.zshrc file.
mkdir ~/.zsh
swift package completion-tool generate-zsh-script > ~/.zsh/_swift
echo -e "fpath=(~/.zsh \$fpath)\n" >> ~/.zshrc
compinitSee Also
Guides
Creating a Swift packageSetting the Swift tools versionAdding dependencies to a Swift packageResolving and updating dependenciesCreating C language targetsUsing build configurationsPackaging based on the version of SwiftBundling resources with a Swift packageReleasing and publishing a Swift packageGenerating Software Bill of Materials (SBOM)Continuous Integration WorkflowsPluginsModule AliasingUsing a package registryPackage Collections