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

[BUG] Completions that include colons get separated in zsh #162

Closed
jaywonchung opened this issue Sep 6, 2020 · 5 comments
Closed

[BUG] Completions that include colons get separated in zsh #162

jaywonchung opened this issue Sep 6, 2020 · 5 comments
Labels
answered bug Something isn't working shell / zsh

Comments

@jaywonchung
Copy link

jaywonchung commented Sep 6, 2020

Describe the bug

I have completions (via the autocompletion keyword argument in Arguments and Options) that include a colon (:) in the string. In zsh, these completions get split into completion candidates and help texts at the colon.

To Reproduce

  • Create a file main.py with:
import typer

images = ["alpine:latest", "nvidia/cuda:10.0-devel-ubuntu18.04"]

def _complete(value: str) -> str:
    for image in images:
        if image.startswith(value):
            yield value

app = typer.Typer()

@app.command("image")
def hello(name: str = typer.Option(..., autocompletion=_complete)):
    typer.echo(name)

if __name__ == "__main__":
    app()
  • Trigger autocompletion with [TAB] on ZSH
$ <app_entrypoint> image --name [TAB]
  • It outputs:
$ <app_entrypoint> image --name [TAB]
alpine       -- latest
nvidia/cuda  -- 10.0-devel-ubuntu18.04

When I cycle through the completion candidates, only alpine and nvidia/cuda gets filled in.

  • But I expected it to output:
$ <app_entrypoint> image --name [TAB]
alpine:latest
nvidia/cuda:10.0-devel-ubuntu18.04

Environment

  • OS: Ubuntu 18.04
  • Typer Version: 0.3.2
  • Python version: 3.7.9
  • Zsh version: 5.4.2 (x86_64-ubuntu-linux-gnu)

Additional context

I tried the exact same thing in Bash, and it worked as expected (the output in "But I expected it to output").

@jaywonchung jaywonchung added the bug Something isn't working label Sep 6, 2020
@alextremblay
Copy link

I don't think this is a bug in typer, I think this is just the nature / default behaviour of the zsh completion system. zsh expects the results of your completetion function to take the form completion_candidate:help_text and formats that output accordingly.
There are ways of getting around that in zsh, like so: https://unix.stackexchange.com/questions/445889/use-colon-as-filename-separator-in-zsh-tab-completion

but I suspect this is beyond the scope of typer's zsh auto-completion support (I'm not a core contributor, i can't speak for them, this is just my two cents)

@tddschn
Copy link

tddschn commented May 15, 2022

@alextremblay I tried the snippet in the link but it didn't work.
I want my autocompletion function to return something like

B6:AA:33:B5:C0:93 -- Lmi 10.0.201.222 0

but got B6 -- AA:33:B5:C0:93 -- Lmi 10.0.201.222 0 instead.

I have no idea how zsh completion works, can you help me configure zsh so that the completions work? Thank you!

@alextremblay
Copy link

@tddschn sadly, no. i think this is something that would need to change in typer's auto-generated zsh autocomplete script.

you could try editing the generated script yourself, but then if you change your CLI's code and need to regenerate autocompletions, your changes will be wiped out

@tiangolo
Copy link
Member

tiangolo commented Nov 7, 2024

Thanks @jaywonchung! This was handled by @snapbug in #988, the fix will be available in version 0.12.6 in the next hours. 🤓 🚀

Copy link

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered bug Something isn't working shell / zsh
Projects
None yet
Development

No branches or pull requests

5 participants