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

Path completion overrides subparser completion #67

Open
Simon-1-1 opened this issue Feb 21, 2022 · 5 comments
Open

Path completion overrides subparser completion #67

Simon-1-1 opened this issue Feb 21, 2022 · 5 comments

Comments

@Simon-1-1
Copy link

My application has a subparser called "build" and the application is generally used inside a directory that contains another directory named "build". I want the subparser to be completed right after the application, like this:

my_app bui
<tab>
my_app build

but instead, I get:

my_app bui
<tab>
my_app build/

That is, there's an unwanted slash at the end, as if it tries to complete the directory. I haven't added shtab.FILE or shab.DIR to the base parser

@casperdcl
Copy link
Collaborator

Interesting... what shell is this on?

@Simon-1-1
Copy link
Author

Bash

@Simon-1-1
Copy link
Author

I think the reason is that we put the filenames option on the final call to complete:

complete -o filenames -F ${root_prefix} ${prog}""").safe_substitute(

I tried removing it but of course filepath completion won't work when it should in that case. Then I tried reverting this change:
https://github.com/iterative/shtab/pull/38/files#diff-495887aece10efc2f1fd9b8dcc23f4c1d445a353018727c6c210c19af8fc4c43L19

and adding the nospace option to complete where the filenames option was before.

Now there is file path completion and my original issue with "build" is solved. The problem is that the nospace option affects normal flags as well, not just incomplete paths. So I have to press space a lot.

So the current behaviour is:

$ my_app bui
<tab>
$ my_app build 

and

$ my_app --give-me-a-path ~/files/com
<tab>
$ my_app --give-me-a-path ~/files/completed

without the nospace option, I'd get a space after completed, even if completed was a directory and I wanted to provide a file within it. This is weird because I added back the -S flag, like I mentioned before:

compgen -f -S "/" -- $1  # files

@Simon-1-1
Copy link
Author

Cannot reproduce anymore. Not sure what causes the difference from before but one change is a newer Ubuntu version, and possibly a new bash version as a result of that. Closing.

@Simon-1-1
Copy link
Author

Simon-1-1 commented Feb 14, 2024

Nope, spoke too soon. Sorry about that. My CWD didn't have a folder named "build" as I had thought. When I create the folder I still see the bug. Re-opening.

Reproduced on two different Ubuntu versions. 23.10 and 22.10.

@Simon-1-1 Simon-1-1 reopened this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants