Generate shell completion for uvx (#7388)

## Summary

Generate shell completion for uvx.

Create a `uvx` toplevel command just for completion by combining `uv
tool uvx` (hidden alias for `uv tool run`) with global arguments. This
explicit combination is needed otherwise global arguments are missing
(if they are missing, clap debug assertions fail when `uv tool run`
arguments refer to global arguments in directives like conflicts with).


Fixes #7258 

## Test Plan

- Tested using bash using `eval "$(cargo run --bin uv
generate-shell-completion bash)"`
This commit is contained in:
bluss 2024-09-17 05:27:19 +02:00 committed by GitHub
parent d1c7cb8bc2
commit e9378be919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 62 additions and 13 deletions

View file

@ -181,6 +181,25 @@ To enable shell autocompletion for uv commands, run one of the following:
Then restart the shell or source the shell config file.
You can also enable shell autocompletion for uvx by running the same commands, replacing `uv` with
`uvx`:
=== "Linux and macOS"
```bash
# Determine your shell (e.g., with `echo $SHELL`), then run one of:
echo 'eval "$(uvx generate-shell-completion bash)"' >> ~/.bashrc
echo 'eval "$(uvx generate-shell-completion zsh)"' >> ~/.zshrc
echo 'uvx generate-shell-completion fish | source' >> ~/.config/fish/config.fish
echo 'eval (uvx generate-shell-completion elvish | slurp)' >> ~/.elvish/rc.elv
```
=== "Windows"
```powershell
Add-Content -Path $PROFILE -Value '(& uvx generate-shell-completion powershell) | Out-String | Invoke-Expression'
```
## Uninstallation
If you need to remove uv from your system, just remove the `uv` and `uvx` binaries: