Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell completion for uvx #7258

Closed
bluss opened this issue Sep 10, 2024 · 0 comments · Fixed by #7388
Closed

Shell completion for uvx #7258

bluss opened this issue Sep 10, 2024 · 0 comments · Fixed by #7388
Labels
cli Related to the command line interface enhancement New feature or request

Comments

@bluss
Copy link
Contributor

bluss commented Sep 10, 2024

uv doesn't ship with any shell completion for the uvx binary.

Here's one solution for bash. Maybe there's a way to include it in uv, or it can help until there's official support.

_uvx() {
    # Requires uv completion to be loaded
    __load_completion uv

    # Complete as if we are uv tool run
    COMP_WORDS=(uv tool run "${COMP_WORDS[@]:1}");
    COMP_CWORD=$((COMP_CWORD + 2));

    _uv "uv";
}

complete -F _uvx -o nosort -o bashdefault -o default uvx
# to make production ready maybe copy the exact complete -F logic from the _uv script, for older bash versions

Install into ~/.local/share/bash-completion/completions/uvx

ilyagr added a commit to ilyagr/uv that referenced this issue Sep 12, 2024
ilyagr added a commit to ilyagr/uv that referenced this issue Sep 12, 2024
ilyagr added a commit to ilyagr/uv that referenced this issue Sep 12, 2024
ilyagr added a commit to ilyagr/uv that referenced this issue Sep 12, 2024
@charliermarsh charliermarsh added enhancement New feature or request cli Related to the command line interface labels Sep 16, 2024
charliermarsh pushed a commit that referenced this issue Sep 17, 2024
## 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)"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command line interface enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants