[Bash-completion-devel] [bash-completion-Bugs][311521] [PATCH] add slash instead of space after dir names in _filedir

bash-completion-bugs at alioth.debian.org bash-completion-bugs at alioth.debian.org
Tue Mar 3 19:27:44 UTC 2009


Bugs item #311521, was opened at 2009-03-02 16:59
Status: Open
Priority: 3
Submitted By: Martin von Gagern (gagern-guest)
Assigned to: Nobody (None)
Summary: [PATCH] add slash instead of space after dir names in _filedir 
Distribution: Gentoo
Originally reported in: None
Milestone: None
Status: None
Original bug number: 


Initial Comment:
I'm unhappy with how completions using _filedir handle directories: they append a space, not a slash. E.g. type "openssl x509 -in /et" and press tab. It will append "c " instead of "c/".

Some other completions, e.g. those shipped with subversion, return an empty COMPREPLY in those cases, falling back to default bash completion. As _filedir adds to the list, doesn't claim to provide the whole list all by itself, and seems to have other benefits besides, I fear simply clearing the list won't easily solve all problems.

I see no official way to tell bash that a given word is to be treated as a prefix, in order to prevent bash from adding a space. Barring modifications to bash itself, we need some way to trick bash into treating a word as incomplete. E.g. we might add "dir/" and "dir/." to the list of completions, so that "dir/" is the common prefix but not the only possible completion, thus preventing the space. This should only be done for single result tokens, as you would not want such artificial duplicate entries when there are multiple real entries to choose from, possibly displayed to the user in a list.

The attached patch against the main git branch addresses this issue.
It consists of the following three changes:
1. append / after directory names
2. omit directories from file listings to avoid duplicates
3. add dir/. if the list consists only of a single dir/ entry

----------------------------------------------------------------------

Comment By: Martin von Gagern (gagern-guest)
Date: 2009-03-03 19:27

Message:
OK, it's not that easy: with that patch in place, the list of alternatives for e.g. mkdir now lists directories with two slashes. The reason seems to be that the complete command for mkdir (and most other callers of _filedir) contains "-o filenames", while that for openssl (and a few others) does not.

Possible solutions:

1. Drop my patch, add -o filenames to affected completions instead. This could cause non-file arguments to be erroneously interpreted as file names.

2. Use my patch, and drom -o filenames from all other affected completions.

3. Provide multiple versions of _filedir and any general purpose function invoking _filedir, like _longopt.

I guess I'm in favor of option 2, as this gives the programmatic completion maximal control over the completion process. Once we agree on a solution, I'd write a patch for it as soon as I find the time.

While investigating this issue, I also noticed that there exists an option "nospace" to prevent the addition of spaces. This might be the cleaner solution to avoid my "/." hack, but would require modifications to almost all completion functions, in order to provide spaces programmatically. I guess I'd prefer the hack over such a major redesign, at least for now.

I've attached a perl script which I've used to investigate the issue. You invoke it using "complete | perl callGraph.pl" from within the directory containing the bash_completion file. It will figure out which functions call which others, and use your current set of completions to list all those that might end up calling _filedir. For each such completion, it lists the completion command (which will give any options) as well as a call graph which might lead to _filedir. Using this tool, you can see which commands will use _filedir and what options are in place for their completions.

----------------------------------------------------------------------

You can respond by visiting: 
http://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311521&group_id=100114



More information about the Bash-completion-devel mailing list