[Bash-completion-devel] _filedir only escaping whitespace when `-o filenames' is in effect?

Freddy Vulto fvulto at gmail.com
Mon Aug 3 20:39:35 UTC 2009


On Sun, Aug 2, 2009 at 9:23 PM, Ville Skyttä<ville.skytta at iki.fi> wrote:
> ...but why wouldn't simply adding $filenames to their "complete" calls be the
> right thing to do?  The above sounds somewhat messy to me and personally I'd
> rather start thinking about getting rid of most of _filedir's current contents
> (when we can assume -o plusdirs) than adding more hair that duplicates
> existing functionality to it.

Because "complete $filenames" carves `-o filenames' in stone for all
the command's completions.  I assume $filenames hasn't been added to
the aforementioned function list because their main intention is NOT
to complete on filenames, yet *sometimes* they whish to do so
- calling _filedir.

Adding $filenames has the side effect that if a completion happens
to have a directory with the same name, a slash will be appended.
Take for example, the `ssh' command which essentially completes on
hostnames.  Adding `-o filenames' would erroneously append a slash
if a directory happens to exist with the same name:

   $ complete -p ssh  # Show current ssh completion has no `-o filenames'
   complete -F _ssh ssh
   $ mkdir localhost
   $ ssh loc<TAB>
   $ ssh localhost    # Correct
   $ complete -o filenames -F _ssh ssh
   $ ssh loc<TAB>
   $ ssh localhost/   # Wrong, slash is appended
   $ rmdir localhost  # Cleanup tmp directory

You only want to add `-o filenames' to ssh completion when completing
specific file-expecting options, like ssh's -F, -i or -S.

I don't see how `-o plusdirs' is going to save us here?  I think our
only saviour is the `compopt' command (bash >= v4) *1) which allows
you to modify completion options for the currently-execution
completion - in contrast to having the options 'carved in stone'.

Unfortunately we don't have `compopt' in bash-3, and I'm reluctant
to add `-o filenames' everywhere - introducing the bug mentioned above.
So I think our only options are to wait for bash-4 or to fix
_filedir working correctly also if `-o filenames' isn't in effect.
Maybe we can even make the new _filedir do some introspection and
make it look for itself if `-o filenames' is in effect - changing
it's behaviour on the fly.

*1)
http://gnu.april.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html

Greetings, Freddy Vulto
http://fvue.nl



More information about the Bash-completion-devel mailing list