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

Tabs after redirecting stdout do not complete files in bash #171

Open
mauvilsa opened this issue Jun 11, 2024 · 1 comment
Open

Tabs after redirecting stdout do not complete files in bash #171

mauvilsa opened this issue Jun 11, 2024 · 1 comment

Comments

@mauvilsa
Copy link

mauvilsa commented Jun 11, 2024

When working in shells it is quite common that a command outputs something to stdout an the user wants to redirect this to a file, for example:

ls > /tmp/list_of_files.txt

Using tab completion after the > redirection is very useful to navigate existing directories or complete files. This works out of the box for commands that don't have any tab completion, since anyway this no longer depends on the command.

Unfortunately, when an shtab completion script is activated, the completion after redirection no longer works. For instance take the following script:

from argparse import ArgumentParser
import shtab

parser = ArgumentParser()
parser.add_argument("--number", type=float)
shtab.add_argument_to(parser, "--shell-completion")
print(parser.parse_args())

The following are cases that work and don't work:

$ cli.py --n<TAB>
$ cli.py --number

$ cli.py > <TAB><TAB>
[BUG: does not complete anything]

$ cli.py >> <TAB><TAB>
[BUG: does not complete anything]

$ cli.py 2> <TAB><TAB>
[BUG: does not complete anything]

$ cli.py --number 1 &> <TAB><TAB>
[OK: completes files]

$ cli.py --number 1 2>&1 <TAB><TAB>
[OK: completes files]

$ cli.py --number 1 | <TAB><TAB>
[OK: completes commands]
@mauvilsa
Copy link
Author

mauvilsa commented Jun 11, 2024

I would be willing to work on a fix. But probably only if I get some guidance since I don't really understand why it doesn't work or know how to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant