Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 417929 - app-shells/bash-completion: some builtin completions don't work with spaces
Summary: app-shells/bash-completion: some builtin completions don't work with spaces
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo Shell Tools project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: bashcomp-spacepath
  Show dependency tree
 
Reported: 2012-05-28 07:10 UTC by poletti.marco
Modified: 2016-01-29 13:40 UTC (History)
9 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description poletti.marco 2012-05-28 07:10:54 UTC
Some builtin bash completions don't work for files/directories with spaces.

See Bug 417717 for more details.
Comment 1 Andreas Prieß 2015-07-13 12:19:11 UTC
I have this problem on a current stable amd64 system since the completions were updated to the new 'all enabled' version.

For example with 'cd': having two dirs to possibly descend to

Harry Potter
Harry-Potter

$ cd H

gets completed to

$ cd Harry

and adding '-' can be completed to Harry-Potter. Adding space like '\ ' can _not_ be completed!

The completion works when the filename is started with a single quote:

$ cd 'Harry

can be completed after adding a space.

The exact same completions work without problems for 'rm' and other commands.
Comment 2 David Flogeras 2015-09-03 18:56:22 UTC
Can anyone point to which file provides the completions for builtins?  Would also be good to see an example of how to fix.  I don't care so much about the more esoteric commands, but having broken 'cd' is really hard to cope with.
Comment 3 Pascal BERTIN 2015-09-15 16:57:21 UTC
I'm not sure exactly if this is the proper way to fix this issue, but if this can help, here is what I did:
in /usr/share/bash-completion/bash_completion:570,
in function _filedir, I changed : 
--
    _quote_readline_by_ref "$cur" quoted
-    x=$( compgen -d -- "$cur" ) &&
+    x=$( compgen -d -- "$quoted" ) &&
    while read -r tmp; do
        toks+=( "$tmp" )
--

Trying to find where the issue came from, I found that compgen -d does not seem to handle well quoted/escaped strings.
compgen -f does (hence, rm completion works, because it does not call "_filedir -d"), so this could be an issue with bash's builtin itself.


Again, as this was my first look at bash-completion, I'm not sure this is the way to go, the only thing I can tell, is that now, things complete as they used to and I haven't found any negative impact of my (recent though) change.
Comment 4 Pascal BERTIN 2015-09-15 16:59:22 UTC
and of course, patch in my comment is backward.

I replaced "$quoted" by "$cur" :-)
Comment 5 Luca Longinotti 2015-10-05 20:09:14 UTC
The fix described in comments #3/4 seems to work. At least the moments of me hitting TAB and being perplexed by nothing happening tend towards zero now. :-) Thanks for sharing your fix!
Comment 6 Soren Harward 2016-01-03 18:26:55 UTC
I consistently hit this bug for trying to "cd" into directories with spaces in the names.
Comment 7 Arnaud Launay 2016-01-17 17:59:55 UTC
I confirm that I hit this bug on at least two different systems, and that Pascal's patch from comment #3 does correct the trouble.
Comment 8 Michal Petrucha 2016-01-29 09:07:18 UTC
I can no longer reproduce this with app-shells/bash-completion-2.1_p20141224-r1, which means the fix for #543100 has probably fixed this as well.
Comment 9 Arnaud Vallette d'Osia 2016-01-29 09:43:00 UTC
same here : all fixed, can not reproduce after bash-completion update either.
Comment 10 Arnaud Launay 2016-01-29 09:50:24 UTC
Confirmed too, although the upstream does include Pascal's patch, and NOT the gentoo used one. Unsure which is best.
Comment 11 Patrice Clement (RETIRED) gentoo-dev 2016-01-29 13:40:20 UTC
Alright folks. Thanks a lot for confirming the patch we put in fixed this issue. Let's close this bug and move on then. :)