error message when no completions and failglob is on

Bug #194419 reported by adw
4
Affects Status Importance Assigned to Milestone
bash-completion (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

Binary package hint: bash

gutsy, bash 3.2-0ubuntu11

mkdir test
cd test
touch test.tar
touch tgz
tar tf <TAB>

Should: autocomplete test.tar
Instead: nothing happens

I noticed this because I have failglob on, and it broke completion even without the tgz file.
I haven't investigated further, but it seems a glob (or probably more than one) in bash_completion isn't quoted properly and expands too early.

Revision history for this message
Jim J (morlockhq) wrote :

I couldn't confirm this on my Gutsy installation.

I used the same steps that adw used, but hitting <TAB> after

tar tf<SPACE><TAB>

autocompleted a "t" and hitting <TAB> again gave me tgz and test.tar as the completion options.

So I typed

mkdir test
cd test
touch test.tar
touch tgz
tar tf<SPACE><TAB>

and I got expected behavior.

However, if I omitted the <SPACE> after tf, I got nothing, so

mkdir test
cd test
touch test.tar
touch tgz
tar tf<TAB>

Results in nothing.

Can anyone else confirm this?

Jim J (morlockhq)
Changed in bash:
status: New → Incomplete
status: Incomplete → New
Revision history for this message
chills42 (chills) wrote :

I was also unable to confirm the original reports steps. I am able to confirm Jim J's reply.

tar tf<TAB>

does not offer any items, however:

tar tf<SPACE><TAB> does offer items for completion as expected.

Revision history for this message
adw (adw) wrote :

Jim, chills42,

It shouldn't complete to tgz at all, so I think you don't have programmable complete enabled.
Try running this line before testing:
. /etc/bash_completion

And it shouldn't complete without the space, I think. It would be expecting more options instead of a filename.

Revision history for this message
Marcel Stimberg (marcelstimberg) wrote :

I can confirm the initial author's report... Typing tar tf<SPACE><TAB> does not offer me any items. The same is true for any other combination of letters ending in an 'f' (i.e. tar ft<SPACE><TAB> works, tar xf<SPACE><TAB>) does not. Deleting the file 'tgz' also solves the issue, i.e. the problem does not occur with only the test.tar file present.

Changed in bash:
status: New → Confirmed
Revision history for this message
Jim J (morlockhq) wrote : Re: [Bug 194419] Re: improper quoting in bash completion script

I can confirm now. After sourcing the /etc/bash_completion file (.
/etc/bash_completion), I get the same behavior as was originally reported by
adw.

On Fri, Feb 22, 2008 at 3:51 PM, adw <email address hidden> wrote:

> Jim, chills42,
>
> It shouldn't complete to tgz at all, so I think you don't have
> programmable complete enabled.
> Try running this line before testing:
> . /etc/bash_completion
>
> And it shouldn't complete without the space, I think. It would be
> expecting more options instead of a filename.
>
> --
> improper quoting in bash completion script
> https://bugs.launchpad.net/bugs/194419
> You received this bug notification because you are a direct subscriber
> of the bug.
>

Revision history for this message
adw (adw) wrote : Re: improper quoting in bash completion script

This trivial patch for /etc/bash_completion fixes the tar issue:
2888c2888
< _filedir $ext
---
> _filedir "$ext"

However, I think I had another (similar) problem with failglob and autocomplete for rm, but I cannot seem to reproduce that now.

Revision history for this message
Marcel Stimberg (marcelstimberg) wrote :

Fixing the quoting as in the patch above, fixes the initial issue (tar autocompletion) for me.

Revision history for this message
adw (adw) wrote :

Ok, I managed to reproduce the rm problem. In fact, this seems to affect all file autocompletes:

mkdir test
cd test
touch [a]
touch a
ls <TAB>

Should: do nothing, list both files as completion options on a second <TAB>
Instead: autocompletes to a

(Again, it breaks autocomplete with failglob even without the a file.)

The problem is caused by the _filedir() function in /etc/bash_completion. There are a couple of lines which temporarily disable globbing, but they are commented out. Uncommenting them fixes the issue for me, and seems to have no ill effects, but I'm sure someone commented them out for a reason...

Revision history for this message
Mika Fischer (zoop) wrote :

This is a bug in the bash-completion package.

Mika Fischer (zoop)
Changed in bash-completion:
assignee: nobody → zoop
status: Confirmed → In Progress
Revision history for this message
Mika Fischer (zoop) wrote :

I've prepared an updated package in my PPA which should fix the bug you reported.

If you're using hardy I'd appreciate it if you could test it and report whether your bug is indeed fixed and also whether you experienced any other regressions.

You can get the package from here:
http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb

To install it:
wget http://launchpadlibrarian.net/13042048/bash-completion_20060301-3ubuntu2%7Eppa2_all.deb
sudo dpkg -i dpkg -i bash-completion_20060301-3ubuntu2~ppa2_all.deb

To go back to the original package, do this:
sudo aptitude install bash-completion/hardy

If I don't get reports of regressions I'll try to get this version into hardy.

Thanks for your help!

Changed in bash-completion:
status: In Progress → Fix Committed
Revision history for this message
adw (adw) wrote :

I'm not using hardy yet, so I can't test (sorry), but I did just find another similar bug:

mkdir test
cd test
touch [a].zip
touch a.zip
unzip <TAB>

Patch attached.

Revision history for this message
Mika Fischer (zoop) wrote :

Thanks, I've fixed this problem too. I've not used your patch but fixed it in a similar way that I fixed the original problem which should cover some additional corner cases. It'll also be in the next upload.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package bash-completion - 20060301-3ubuntu2

---------------
bash-completion (20060301-3ubuntu2) hardy; urgency=low

  * Bugfix release:
   - Fix _get_cword more
   - Fix _command function to correctly prune the command line (LP: #103395)
   - Remove newline from options pattern for dpkg (LP: #138312)
   - Start readline-quoting arguments to compgen (LP: #123665)
   - Save and restore -v shell option (LP: #205444)
   - Prevent glob expansion in _filedir function (LP: #194419)
   - Quote glob expression in tar completion function (LP: #194419)
   - Complete AAS/SSA files for mplayer -sub (LP: #151086)
   - Disable completion of postgresql users and databases (LP: #164772)
   - Use files from UserKnownHostsFile options in addition to standard ones
     (LP: #211180)

 -- Mika Fischer <email address hidden> Sat, 05 Apr 2008 16:09:34 +0200

Changed in bash-completion:
status: Fix Committed → Fix Released
Revision history for this message
adw (adw) wrote :

Ah, crap. Just moved to hardy, and it's still broken.

shopt -s failglob
mkdir test
cd test
unzip <TAB>

Revision history for this message
adw (adw) wrote :

Never mind, somehow extglob had gotten unset! (A changed default?)

Revision history for this message
adw (adw) wrote :

...Although even with extglob, this still seems to fail:

shopt -s failglob
mkdir test
cd test
vim <TAB>

Revision history for this message
Mika Fischer (zoop) wrote :

Ah, sorry, I did not get that part of the bug.

It's an easy fix, but I'm afraid it's too late for hardy...

If you want, you can apply the attached one-line patch.

Changed in bash-completion:
status: Fix Released → Fix Committed
Revision history for this message
adw (adw) wrote :

Thanks, that fixed it.

Revision history for this message
adw (adw) wrote :

I'm afraid we're not quite done yet ;)

shopt -s failglob
sudo <TAB>

Revision history for this message
adw (adw) wrote :

Also,

shopt -s failglob
ls *<TAB>

Revision history for this message
Mika Fischer (zoop) wrote :

Sigh, more quoting errors... :)

Patch attached.

Revision history for this message
adw (adw) wrote :

Completion for 'man' gives directories instead of manpages with failglob.

Revision history for this message
adw (adw) wrote :

And here's a patch.

Revision history for this message
nqzero (nqzero) wrote :

thanks mika / adw - i've been fighting this for a while. in 7.10 i got around it by selectively enabling completion, but this is a whole lot nicer. but then 8.04 broke my work-around. once i narrowed it down to the failglob shopt i found your page. i just applied the patches and things are working much nicer.

for the sake of anyone googling, i was seeing:

i would type: sudo apt-get <TAB>
and i'd see: sudo apt-get bash: no match: COMP_WORDS[2-1]

the patches above fix it for me.

is there an easy way to "force" a completion, eg so that i could run it with a -x option or with bashdb ? i'm sure i'll find a few more of these problems :)

Revision history for this message
nqzero (nqzero) wrote :

seems to ignore expand-tilde

lytles@bryan| bind -V | grep tilde
expand-tilde is set to `off'

typing: ls ~/<TAB>
------> ls /home/lytles

if i don't source the patched /etc/bash_completion, bash leaves the ~ alone.

looks like the problem is in the function _expand(), but i haven't found a workaround yet

Revision history for this message
nqzero (nqzero) wrote :

ok - have a patch for the tilde expansion

it doesn't honor readlines expand-tilde, it just forces things to stay in tilde notation. might get a refinement later, but it's friday evening :)

Revision history for this message
nqzero (nqzero) wrote :

completion for cvs seems broken :

> complete | grep cvs
complete -o default -F _cvs cvs

> ls src/
com CVS hpctest2

> cvs diff src<TAB>
    --> cvs diff src<space> instead of the possible completions

at first glance this one looks beyond me.

Revision history for this message
nqzero (nqzero) wrote :

another: trying to prefix a grep with a find

grep -r "stuff.*stuff"

then add at the beginning "find comp" and hitting tab

find com<tab>grep -r "stuff.*stuff"

this kills the current line (and it doesn't even go to history, so potentially you could lose a significant amount of work if you'd been building up a big line)

here's what you see after tab:
>find combash: no match: "stuff.*stuff"
>

this should complete correctly (i understand it's a corner), but at worst it should do nothing (and never kill without history the entire line).

here's my shopt -p:

shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -s checkwinsize
shopt -s cmdhist
shopt -u compat31
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extdebug
shopt -s extglob
shopt -s extquote
shopt -s failglob
shopt -s force_fignore
shopt -u gnu_errfmt
shopt -u histappend
shopt -u histreedit
shopt -u histverify
shopt -u hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lithist
shopt -u login_shell
shopt -u mailwarn
shopt -u no_empty_cmd_completion
shopt -u nocaseglob
shopt -u nocasematch
shopt -s nullglob
shopt -s progcomp
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -u sourcepath
shopt -u xpg_echo

Revision history for this message
adw (adw) wrote :

Since Mika seems to be gone for a bit, meanwhile you can work around the bugs by putting this at the start of the broken functions:
local glob=`shopt -p failglob`; shopt -u failglob
And this before every return and at the end:
eval $glob

(Maybe you've done something similar already. :)

Mika Fischer (zoop)
Changed in bash-completion:
importance: Undecided → Medium
status: Fix Committed → Triaged
Revision history for this message
nqzero (nqzero) wrote :

jc - this is still fubar in hardy

Mika Fischer (zoop)
Changed in bash-completion:
assignee: zoop → nobody
Revision history for this message
Martin Mai (mrkanister-deactivatedaccount-deactivatedaccount) wrote :

bash-completion version 20080705 has been merged from Debian for Jaunty and fixes many many bugs. Since the original issue the reporter mentioned is fixed (and as far as I can see, some other ones mentioned in the comments, too), I am closing this bug. Please summarize which wrong completions stated in this bug report are still there and open a new bug for them. Thanks in advance.

Changed in bash-completion (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.