Path completion overrides subparser completion
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
Interesting... what shell is this on?
Bash
I think the reason is that we put the filenames option on the final call to complete: https://github.com/iterative/shtab/blob/7f25585e4b7a5552daeb1cc03d857108332f1a86/shtab/init.py#L431
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
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.
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.