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] MSYS2 Bash and Git Bash for Windows autocomplete get ^M between autocomplete options #202

Open
aslakrin opened this issue Dec 5, 2020 · 2 comments
Labels
bug Something isn't working os / windows Related to Windows shell / bash

Comments

@aslakrin
Copy link

aslakrin commented Dec 5, 2020

Describe the bug

Somewhere along the line it seems an \r gets introduced between the available options in git bash on windows. This is also the case for MSYS2. Seems not to be for zsh under msys2.

To Reproduce

Steps to reproduce the behavior with a minimum self-contained file.

Replace each part with your own scenario:

  • Create a file main.py with:
import typer

app = typer.Typer()


@app.command()
def hello(name: str):
    typer.echo(f"Hello {name}")

@app.command()
def goodbye(name: str):
    typer.echo(f"Goodbye {name}")

if __name__ == "__main__":
    app()
  • Call it with:
typer main.py run <TAB><TAB>
  • It outputs:
goodbye^M  hello      
  • But I expected it to output:
goodbye hello      

Expected behavior

I do not expect extra carriage returns to appear as control characters

Environment

  • OS: Windows
  • Typer Version 0.3.2
  • Python version 3.8.3

Additional context

Operates normally when APP_COMPLETE=complete_bash $1 ) is changed to APP_COMPLETE=complete_bash $1 | tr -d '\r' ) in the completion file, but this is probably not a good fix.

@aslakrin aslakrin added the bug Something isn't working label Dec 5, 2020
@Pack3tL0ss
Copy link

Pack3tL0ss commented May 5, 2022

Appreciate the great tools

I think this is the same as what I'm seeing. It appears to have started with click v8.0.0, if I pin to click v7.1.2 bash completion works as expected.

completion was refactored in click 8. I don't know if issue lies w/ typer or click, but ^M is always injected into the completion.

$ cencli show
^M          aps         clients     dhcp        gateways    interfaces  logs        sites       tokens      vlans       wlans
alerts      branch      config      events      groups      last        routes      switches    upgrade     webhooks
all         certs       devices     firmware    hook-proxy  lldp        run         templates   variables   wids

The ^M breaks completion you always have to type the full word.
Again: click v7.1.2 works
click >=8.0.0 exhibits the issue.

Expect this may be an issue with click upstream, but hopefully we can get it sorted out.

There was another impact to click 8.x re completion, and this appears to impact all shells.
I have a ton of custom completion functions, all were setup like this:

# app.command defines custom completion func:
#  _group: str = typer.Option(None, "--group", autocompletion=cli.cache.group_completion,)

    def group_completion(
        self,
        incomplete: str,
        args: List[str] = None,
    ):
        match = self.get_group_identifier(
            incomplete,
            completion=True,
        )
        out = []
        if match:
            for m in sorted(match, key=lambda i: i.name):
                if m.name not in args:
                    out += [tuple([m.name, m.help_text])]

        for m in out:
            yield m[0], m[1]

prior to click 8
cencli move barn.3 --group <tab><tab> would provide ['move', 'barn.3', '--group'] as args to the completion function.
Since click 8 args is always []

They all show up in the ctx.params (values()), but that's a lot of re-factoring.

@Pack3tL0ss
Copy link

@tiangolo do we need to open an issue (may already be one) with click? It was def something in click 8 that causes the behavior, but not sure if it's an issue with typers interaction or if click actually broke completion on bash with click 8?

Same for the args parameter in the completion functions. If click 8 is in use args is always an empty list as described above.

Thanks for the great work/tools!

@svlandeg svlandeg added os / windows Related to Windows shell / bash labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working os / windows Related to Windows shell / bash
Projects
None yet
Development

No branches or pull requests

3 participants