[Bash-completion-devel] how do you filter out matches even if there are files with * in their name?

Peter Cordes peter at cordes.ca
Wed Dec 3 23:03:34 UTC 2014


_filedir_xspec doesn't get this right:

touch foobar.Z 'foo*'

compress f[TAB] => foo[TAB] => foo* foobar.Z
compress foob[TAB] => nothing (as it should be, you shouldn't compress(1) a .Z)


 I started off looking for cases where $(command ls) could be replaced
with a glob, but it only took me about 3 files before I ran into one
in horrible shape, with all kinds of problems:  completions/cvs.  lack
of quoting on variable expansions, not safe even for spaces in
filenames, etc.

 Anyway, was working on the cvs add completion.  Replaced the loop
with an associative array check, but it turns out there doesn't seem
to be a way to generate COMPREPLY with compgen if you have filenames
with * in them, if that filename taken as a glob expression matches
some other filenames.  Is that right, or am I missing something?

${files[@]} is perfect up until I hit
COMPREPLY=( $( compgen -X "$_backup_glob" -W '"${files[@]}"' \
		-- "$cur" ) )

 Then it breaks.  Either glob expansion happens somewhere in there, or
not enough quote-removal happens to get rid of all the quoting I had
to use to stop glob expansion.

    printf -v files[i] %q "${files[i]}"  results in
 foo\* in the output, then foo\\\\\*  or something.

 '"\${files[@]}"'  breaks, too.

 So is it just me, or is compgen generally pretty horrible to use?

-- 
#define X(x,y) x##y
Peter Cordes ;  e-mail: X(peter at cor , des.ca)

"The gods confound the man who first found out how to distinguish the hours!
 Confound him, too, who in this place set up a sundial, to cut and hack
 my day so wretchedly into small pieces!" -- Plautus, 200 BC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 359 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20141203/0305db1d/attachment.sig>


More information about the Bash-completion-devel mailing list