typer icon indicating copy to clipboard operation
typer copied to clipboard

[BUG] Typer CLI and Packages not auto-completing

Open theFong opened this issue 4 years ago • 8 comments

First check

  • [x] I used the GitHub search to find a similar issue and didn't find it.
  • [x] I searched the Typer documentation, with the integrated search.
  • [x] I already searched in Google "How to X in Typer" and didn't find any information.
  • [x] 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%   

theFong avatar Oct 21 '20 20:10 theFong

I have the same problem on Arch Linux. My application is named differently, no naming conflict with an existing one. I also checked, the file is created in .zfunc.

max-tet avatar Feb 19 '21 22:02 max-tet

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.

everdark avatar Feb 26 '21 16:02 everdark

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

ssbarnea avatar Apr 02 '21 17:04 ssbarnea

I am using Prezto not powerlevel10k, and I have that same problem.. I tried everything suggested in the thread still not working.. Adding compinit -D at the end of my ~/.zshrc file results in:

(eval):1: bad pattern: ^[[H^[[2J^[[3J_arguments
sh: cls: command not found
(eval):1: bad pattern: ^[[H^[[2J^[[3J_arguments
sh: cls: command not found
(eval):1: bad pattern: ^[[H^[[2J^[[3J_arguments

flight505 avatar Aug 12 '21 13:08 flight505

Hi guys, I'm having the same error on my Ubuntu 20.04 VM. Is there any update on how to solve the problem?

rolldeep avatar Sep 01 '21 14:09 rolldeep

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

I've tried that and I got no changes at all.

rolldeep avatar Sep 01 '21 14:09 rolldeep

Hi guys, any news about this issue??

roniel-rhack avatar Dec 26 '23 19:12 roniel-rhack

Could you check whether https://github.com/tiangolo/typer/pull/801 solves your issue?

svlandeg avatar May 03 '24 14:05 svlandeg

Hi all, the zsh autocompletion feature should be fixed with PR https://github.com/tiangolo/typer/pull/237. The fix is similar to what @everdark suggested 🙏

svlandeg avatar Jul 01 '24 09:07 svlandeg