question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Typer CLI and Packages not auto-completing

See original GitHub issue

First check

  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google “How to X in Typer” and didn’t find any information.
  • I already searched in Google “How to X in Click” and didn’t find any information.

Description

I have built a CLI with with Typer and have been really enjoying using this library. I am looking to setup the auto complete feature but have run into something unexpected. When installing my package, running --install-completion, and restarting the terminal it would “auto complete” to files/dirs in my current directory (not expected behavior). To test whether there was something mis-configured on my end I tested the auto complete or the Typer CLI by running typer --[TAB][TAB] which did not auto complete to anything.

I’m not sure if there is something wrong with my environment, Typer CLI, my code, or misunderstanding how auto-completion works.

Additional context

I am on OSX and have noticed naming conflict with another program called typer.

I have tested auto complete on this code that I have run with typer [name.py] run --[TAB][TAB]

import typer


def main(name: str = typer.Option("World", help="The name to say hi to.")):
    typer.echo(f"Hello {name}")


if __name__ == "__main__":
    typer.run(main

Here is the bottom of my .zshrc. I can confirm

# tabtab source for packages
# uninstall by removing these lines
[[ -f ~/.config/tabtab/__tabtab.zsh ]] && . ~/.config/tabtab/__tabtab.zsh || true

autoload -Uz compinit
zstyle ':completion:*' menu select
fpath+=~/.zfunc

Happy to post my full zshrc if it would help!

Can Also confirm that zfunc _typer exists

#compdef typer

_typer_completion() {
  eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _TYPER_COMPLETE=complete_zsh typer)
}

compdef _typer_completion typer%   

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
ssbarneacommented, Apr 2, 2021

Things I had to do to make completion work, in case it may help someone else:

  • be sure you do not print anything to stdout (logging does that in default config!) or the generated script may endup being broken
  • I had to add compinit -D at the end of my ~/.zshrc file. Without it completion would not have worked
2reactions
everdarkcommented, Feb 26, 2021

I have faced similar issue today with zsh and powerlevel10k prompt. I managed to solve the problem by moving the following section

zstyle ':completion:*' menu select
fpath+=~/.zfunc

in my ~/.zshrc file to near top (right after the initiation of powerlevel10k prompt) from the bottom.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLI Option autocompletion - Typer - tiangolo
To check it quickly without creating a new Python package, install Typer CLI. ... Right now we get completion for the CLI option...
Read more >
Terminal autocomplete doesn't work properly - Ask Ubuntu
So you type partial of commands and by hitting Tab we get a auto completion of commands. Installation. Step 1: Install bash-completion $...
Read more >
typer - Bountysource
[BUG] Typer CLI and Packages not auto-completing $ 0 ... Created 2 years ago in tiangolo/typer with 2 comments. First check. [x] I...
Read more >
How to enable shell autocompletion automatically after ...
On the other way, some packages like git and docker provide ... Interestingly, some other python CLI frameworks like typer provides a way...
Read more >
Turn auto complete on for Mac Terminal - Edward Beazer Blog
Autocomplete will fill in the rest of your command with available options when you press the tab key while typing. This feature will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found