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

can't get --install-completion to work #54

Closed
zzztimbo opened this issue Mar 3, 2020 · 9 comments
Closed

can't get --install-completion to work #54

zzztimbo opened this issue Mar 3, 2020 · 9 comments
Labels
bug Something isn't working shell / zsh

Comments

@zzztimbo
Copy link

zzztimbo commented Mar 3, 2020

given this program:

#!/usr/bin/env python
  port typer

app = typer.Typer()

@app.command()
def foo():
    print('foo')

@app.command()
def bar():
    print('bar')

if __name__ == "__main__":
    app()

I run: ./foo.py --install-completion

I see:

zsh completion installed in /Users/tchan/.zshrc.
Completion will take effect once you restart the terminal.

I source my .zshrc and then type ./foo.py and hit tab

I see this:

./foo.py env: foo.py: No such file or directory

@zzztimbo zzztimbo added the bug Something isn't working label Mar 3, 2020
@DarkaMaul
Copy link

Actually, there is a bug with the generation because the full path of the app file (foo in your case) is not written.

Temp workaround:
Replace the generated line (in ~/.zshrc) by the following one:

eval $(env COMMANDLINE="${words[1,$CURRENT]}" _APP.PY_COMPLETE=complete-zsh python PATH_TO_FOO/foo.py)

You could also report the bug to Click-Completion

@tiangolo
Copy link
Member

Hi everyone! Thanks for the discussion here.

For auto completion to work, you have to create a Python package, there's a new section in the docs about that: https://typer.tiangolo.com/tutorial/package/ 📝

If you just want to run simple scripts and have completion in your shell, you can use the new Typer CLI: https://typer.tiangolo.com/typer-cli/ 🚀 ⌨️

@github-actions
Copy link

Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.

@ShivKJ
Copy link

ShivKJ commented Aug 18, 2021

I am still facing the same issue. Let me know if this has been resolved

@shelper
Copy link

shelper commented Aug 18, 2021

same here, i have a tool called zetta, that i made it a command line tool with [tool.poetry.scripts]
I run poetry install, and then which zetta, shows me where the zetta executable is
then i run zetta --install-completion zsh, and got message confirmed and in my ~/.zfunc/_zetta i have

_zetta_completion() {
eval $(env COMMANDLINE="${words[1,$CURRENT]}" _APP.PY_COMPLETE=complete-zsh zetta)
}

but the autocompletion still does not work....

same steps for bash works...

@shelper
Copy link

shelper commented Aug 18, 2021

well , i think i solved this problem by adding the following lines to my .zshrc
hope this helps

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

@paw-lu
Copy link

paw-lu commented Feb 22, 2022

I'm still not able to get completion to work.

My setup is pretty much identical to @shelper

My (entire) ~./zshrc:

# ~/.zshrc
autoload -Uz compinit
fpath+=~/.zfunc
compinit

My ~/.zfunc/_nbpreview:

#compdef nbpreview

_nbpreview_completion() {
  eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _NBPREVIEW_COMPLETE=complete_zsh nbpreview)
}

compdef _nbpreview_completion nbpreview

Seems the correct file is registered,
but when it comes to actual completion,
nothing happens.

# Command to show which completion file is registered
% whence -v $_comps[nbpreview]
_nbpreview_completion is a shell function from /Users/pawlu/.zfunc/_nbpreview

% nbpreview --<TAB>
# No output, completion

@wpm
Copy link

wpm commented Aug 14, 2022

From here I got the workaround to add compinit -D to the end of my .zshrc file. I have no idea what it means, but it worked.

@svlandeg
Copy link
Member

svlandeg commented Jul 1, 2024

Related PR to fix autocompletion with the zsh shell, similar to the fix @shelper mentioned: #237

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

No branches or pull requests

8 participants