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

TAB completion is giving local directory files where command is called. #535

Closed
7 tasks done
Karthik1610 opened this issue Jan 16, 2023 · 8 comments · Fixed by #237
Closed
7 tasks done

TAB completion is giving local directory files where command is called. #535

Karthik1610 opened this issue Jan 16, 2023 · 8 comments · Fixed by #237
Labels
bug Something isn't working shell / zsh

Comments

@Karthik1610
Copy link

Karthik1610 commented Jan 16, 2023

First Check

  • I added a very descriptive title to this issue.
  • 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 read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

#!/usr/bin/env python3
import typer

mgmt_ip_cfg_app = typer.Typer(help="Management Interface Configuration", no_args_is_help=True)

@mgmt_ip_cfg_app.command("Ipv4",
    no_args_is_help=True)
def ipv4_cfg(
            ip: str = typer.Argument(...),
            gateway: str = typer.Argument(...),
            prefixlen: str = typer.Argument(...)):
    pass


@mgmt_ip_cfg_app.command("Ipv6",
    no_args_is_help=True)
def ipv6_cfg(
            ip: str = typer.Argument(...),
            gateway: str = typer.Argument(...),
            prefixlen: str = typer.Argument(...)):
    pass

def main():
    mgmt_ip_cfg_app()

if __name__ == '__main__':
    main()

Description

Hi,

I am new to typer. Kindly point me to doc/issue if this issue is already resolved.
I have written a small cli completion code tmp.py and executed "./tmp.py --install-completion bash".

When i tried to do tab completion , if no files are there tmp.py is repeating "./tmp.py Ipv4 tmp.py tmp.py" or if any files is there, they are getting displayed in the directory where i am calling this script. Could you please help me to resolve this. I am expecting if the last command is reached it should either display help on TAB or dont display anything so that user will enter to get help.

If there are local files, TAB after Ipv4, they are getting displayed.
[root@Linux]# ./tmp.py Ipv4
1       tmp.py

Operating System

Linux

Operating System Details

No response

Typer Version

0.7.0

Python Version

3.6.8

Additional Context

No response

@Karthik1610 Karthik1610 added the question Question or problem label Jan 16, 2023
@relativityhd
Copy link

Hi,
I had the same issue. I had the wrong order of zsh-completion commands in my .zshrc. Try to add this to your .zshrc:

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

Thanks @shelper #54 (comment)

@roniel-rhack
Copy link

Same issue, not resolved yet

@svlandeg svlandeg added shell / zsh bug Something isn't working and removed question Question or problem labels Jul 1, 2024
@svlandeg
Copy link
Member

svlandeg commented Jul 1, 2024

Thanks for the report! For the zsh shell, this should be fixed with #237, which essentially contains the same fix as @relativityhd mentioned here.

@Zhang-Zelong
Copy link

I've tried the #237, but not resolved yet. Version: typer == 0.12.3
Here is my .zshrc about completion.

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

When I do same thing with the document, my shell can only dispaly the file in current dictory after pressing [tab] [tab]

@svlandeg
Copy link
Member

svlandeg commented Aug 5, 2024

@Zhang-Zelong: can you remove the second line from your .zshrc (take a backup first), restart the console, and try again? The file should look like this:

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

@Zhang-Zelong
Copy link

Zhang-Zelong commented Aug 6, 2024

Okay! That works for me, thank you.
So is it a special case or a common bug? Should we fix this snippets in this file typer/_completion_shared.py ?

@svlandeg
Copy link
Member

svlandeg commented Aug 6, 2024

It's a known bug that has already been fixed by PR #237, but requires a final review before it will be merged into master and released with the next Typer update.

@tiangolo
Copy link
Member

Thanks all! This was handled in #237, it will be available in Typer 0.12.4, released in the next hours. 🎉

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

Successfully merging a pull request may close this issue.

6 participants