[Bash-completion-devel] Bug#272660: bash: completion of env vars broken (leading slash is added)
Morita Sho
morita-pub-en-debian at inz.sakura.ne.jp
Sun Sep 14 07:27:41 UTC 2008
Hi,
> Well, an option would really be using $dirnames (i.e. -o dirnames) instead of
> $filenames. But that has drawbacks:
>
> $ cd $H<TAB>
> $HISTCMD $HISTFILE $HISTSIZE $HOSTNAME $HUSHLOGIN
> $HISTCONTROL $HISTFILESIZE $HOME $HOSTTYPE
> $ cd $HOM<TAB>
> $ cd $HOME
>
> $ cd /tm<TAB>
> $ cd /tmp<TAB>
> $ cd /tmp
>
> ..while one would expect it to be /tmp/, so that the following <TAB> would show
> subdirectories... that's what -o filenames (or $filenames, in the file) does:
> adding a trailing backslash.
>
> I'm thinking to a way of adding the / to only directories, by not using
> $filenames.. someone is working behind the curtains ;)
I have some ideas to resolve this problem.
1) Remove -o filenames and emulate what -o filenames does in bash-completion,
in fact, add -S "/" option to `compgen -d` and add -S " " to `compgen -f`.
An attached patch emulate_-o_filenames.patch implements this behavior.
2) Or, remove -o filenames and dynamically enable -o filenames flag if needed.
According to the source code of Bash, compgen -f causes to set 1 to
rl_filename_completion_desired, which is Bash's internal variable for -o
filenames flag.
It is undocumented behavior but it works fine for me.
An attached patch enable_-o_filenames_dynamically.patch implements this behavior.
IMO, 2) looks better because 1) has small drawbacks as described below.
With -o filenames enabled:
$ cd /usr/[TAB]
X11R6/ i586-mingw32msvc/ lib64/ sbin/
bin/ include/ libexec/ share/
games/ lib/ local/ src/
Without -o filenames:
$ cd /usr/[TAB]
/usr/X11R6/ /usr/include/ /usr/local/
/usr/bin/ /usr/lib/ /usr/sbin/
/usr/games/ /usr/lib64/ /usr/share/
/usr/i586-mingw32msvc/ /usr/libexec/ /usr/src/
As you can see Bash automatically strips leading /usr/ when -o filenames are
enabled. I think, however, that implement the emulation for this behavior in
bash-completion is impossible.
Thanks,
--
Morita Sho <morita-pub-en-debian at inz.sakura.ne.jp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: emulate_-o_filenames.patch
Type: text/x-patch
Size: 1529 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20080914/42a7d8bb/attachment-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: enable_-o_filenames_dynamically.patch
Type: text/x-patch
Size: 667 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20080914/42a7d8bb/attachment-0003.bin
More information about the Bash-completion-devel
mailing list