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

_filedir completion for paths with spaces is broken #378

Open
eli-schwartz opened this issue Jan 1, 2020 · 2 comments
Open

_filedir completion for paths with spaces is broken #378

eli-schwartz opened this issue Jan 1, 2020 · 2 comments

Comments

@eli-schwartz
Copy link

eli-schwartz commented Jan 1, 2020

Since commit da99bc5, completions are no longer built by joining together the result of compgen -f -X ... and compgen -d; instead, -o plusdirs is used.

The problem is that the quoted ref we're trying to complete won't complete directory names, only filenames. Test case:

$ mkdir -p "foo bar"/{one,two} && touch "foo bar"/{file1.txt,one/file2.txt}
$ compgen -f -X '!*.@(@(TXT|txt))' -o plusdirs -- foo\\\ bar/
foo bar/file1.txt
$ compgen -f -X '!*.@(@(TXT|txt))' -o plusdirs -- "foo bar/"
foo bar/file1.txt
foo bar/two
foo bar/one
# if the final directory ending in "/" has no spaces, it works
$ compgen -f -X '!*.@(@(TXT|txt))' -o plusdirs -- foo\\\ bar/one/
foo bar/one/file2.txt
# if there is no -X $xspec then it works
$ compgen -f -o plusdirs -- foo\\\ bar/
foo bar/file1.txt
foo bar/two
foo bar/one

I'm not sure why bash returns results this way, or whether it's also a bash bug, but it's currently impossible to descend into subdirectories of a directory with spaces in the name when using a _filedir $xspec.

Tested on Arch Linux with bash-completion 2.10-1 and bash 5.0.011-2, and verified by running compgen against bash 3 and 4 via shbot on Freenode, so if bash is doing wrong here, it seems like it has for an awful long time.

@eli-schwartz
Copy link
Author

eli-schwartz commented Jan 1, 2020

I'm curious why these escapes even exist. If I replace the variable $quoted with $cur, then my original _filedir using completion works fine as per example 2. What utility does the \\\ add?

@scop
Copy link
Owner

scop commented Jan 2, 2020

I have no idea offhand, and quite probably not even after looking at the code. It's entirely possible that the reasoning is a relic from bash 2.x times and hasn't mattered for a long time.

I've contemplated just stopping using _filedir altogether and deprecating it for a bunch of times already, as I don't even remember what good does it actually bring when it works properly, and it has its quirks. But every time I've considered, something (which escapes me at the moment, too) has prevented me from doing that.

Anyway, it's pretty clear already that any further changes to it must come with a bunch of test cases.

hramrach added a commit to hramrach/bash-completion that referenced this issue Sep 30, 2021
…all for files"

This reverts commit da99bc5.

References: scop#378 boo#1167952

The solution without calling compgen -d proves unrealiable.

Until this is fixed revert to calling compgen -d for completions with
file pattern.
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

2 participants