[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
Mon Apr 25 11:24:58 UTC 2011


Bugs item #311521, was changed at 2009-03-02 18:59 by Ville Skyttä 
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311521&group_id=100114

>Status: Closed
Priority: 3
Submitted By: Martin von Gagern (gagern-guest)
>Assigned to: Ville Skyttä  (scop-guest)
Summary: [PATCH] add slash instead of space after dir names in _filedir 
Distribution: Gentoo
Originally reported in: None
>Milestone: 1.3
>Status: Fix Committed
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: Ville Skyttä  (scop-guest)
Date: 2011-04-25 14:24

Message:
I think this has been addressed now at least in 1.3 (possibly even earlier to some extent) where -o filenames is dynamically turned on when needed.

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

Comment By: Ville Skyttä  (scop-guest)
Date: 2009-03-03 22:19

Message:
I'd be in favour of 1) (basically s/$default/$filenames/) for consistency.  Then, if someone comes up with something definitely better later, do it all over the place in one fell swoop.

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

Comment By: Martin von Gagern (gagern-guest)
Date: 2009-03-03 21: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: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311521&group_id=100114



More information about the Bash-completion-devel mailing list