<div dir="ltr">Hello,<div>Thanks for Raphael's answer,  so ... maybe my bash-completion's version in my Debian GNU/Linux is too old,  I will update it by myself and  try it again, thanks again :)</div><div>Regards,</div>
<div>Peter</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-02-11 20:16 GMT+08:00 Raphaël <span dir="ltr"><<a href="mailto:raphael.droz@gmail.com" target="_blank">raphael.droz@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, Feb 05, 2014 at 12:06:08PM +0800, Dave Hello wrote:<br>
> I wanna ask to remove_expand() function in bash_completion, because bash<br>
> already have the function (ref:<br>
> <a href="http://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" target="_blank">http://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html#Readline-Init-File-Syntax</a>),<br>

> just set  expand-tilde on and it will works fine,<br>
<br>
<br>
</div>I don't see such a remove_expand() function in bash-completion (git master)<br>
<br>
There is a  __expand_tilde_by_ref which is used by:<br>
- mutt, to check config files exist (not sure it's the expansion is<br>
  needed here)<br>
  (<a href="https://alioth.debian.org/tracker/index.php?func=detail&aid=312759&group_id=100114&atid=413095" target="_blank">https://alioth.debian.org/tracker/index.php?func=detail&aid=312759&group_id=100114&atid=413095</a>)<br>

<br>
- _known_hosts_real(), which extracts ssh *hosts* directives, then check<br>
  these files (can't tell why it's needed here).<br>
<br>
<br>
Secondly, there is an _expand() function which is heavily used.<br>
(namely: bzip2 dd dpkg find gcc gzip info lrzip lz4 lzma lzop man mutt<br>
povray rsync ssh sshfs umount.linux xz zopfli)<br>
<br>
<br>
There, the comment state:<br>
> # Expand ~username type directory specifications.  We want to expand<br>
> # ~foo/... to /home/foo/... to avoid problems when $cur starting with<br>
> # a tilde is fed to commands and ending up quoted instead of expanded.<br>
<br>
<br>
My guess is that the benefit of this function is to expand arguments<br>
when compopt -o filenames is *not* used because readline expansion<br>
*only* applies to the built-in filename completion.<br>
<br>
<br>
The code in its current state is consistent with the facts :<br>
$ ls ~/<TAB><br>
# is *not* expanded<br>
<br>
$ find ~/<TAB><br>
# is expanded<br>
<br>
$ bind 'set expand-tilde on';<br>
$ notexist ~/<TAB><br>
# is expanded<br>
<br>
$ bind 'set expand-tilde off';<br>
$ notexist ~/<TAB><br>
# is *not* expanded<br>
<br>
but it does not explain the reason for this inconsistency between `ls` and<br>
`find`.<br>
<br>
See also:<br>
<a href="http://superuser.com/questions/442765/why-does-bash-tab-expand-a-tilde-when-i-am-completing-a-vim-file-name" target="_blank">http://superuser.com/questions/442765/why-does-bash-tab-expand-a-tilde-when-i-am-completing-a-vim-file-name</a><br>

<br>
So the question could be:<br>
> "why expand continues if I disabled expand-tilde" ... "when it's<br>
> apparently not useful for the completion process itself ?"<br>
<br>
I don't have the answer, but see:<br>
<a href="http://www.linuxquestions.org/questions/linux-software-2/how-to-stop-bash-from-replacing-~-with-home-username-643162/" target="_blank">http://www.linuxquestions.org/questions/linux-software-2/how-to-stop-bash-from-replacing-~-with-home-username-643162/</a><br>

then:<br>
<a href="https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/622403" target="_blank">https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/622403</a><br>
which is outdated since the `_rl_enabled expand-tilde` check is not used<br>
in __expand_tilde_by_ref() anymore.<br>
<br>
At some point the whole expansion mechanism was disabled:<br>
<a href="https://alioth.debian.org/tracker/index.php?func=detail&aid=311431&group_id=100114&atid=413095" target="_blank">https://alioth.debian.org/tracker/index.php?func=detail&aid=311431&group_id=100114&atid=413095</a><br>

(side note: why isn't the tracker public anymore ?!)<br>
... then re-enabled.<br>
<br>
Last thing, according to fdb080ff8 commit message, it seems that using<br>
_tilde() rather than _expand() respects the expand-tilde setting for<br>
filenames. _filedir() which relies on it prove that:<br>
The  $1 != */* in _tilde exclude tilde-expansion in paths (ccbf141e). I don't know<br>
if it was the "right-way" to avoid abusive tilde-expansions as it was<br>
to be the objective according to the commit message.<br>
More of this _expand || return date back from 2010 (and sometimes far<br>
further), before _tilde() existed, this may be a simple explanation.<br>
<br>
<br>
<br>
In the end I join myself to your question, stated in a different fashion:<br>
Why the `find` completion relies on _expand || return 0 when most<br>
others, while providing a filename completion too, do not. (eg: `cd`) ?<br>
<br>
<br>
regards<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
GPG id: 0xD7F62B21<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Bash-completion-devel mailing list<br>
<a href="mailto:Bash-completion-devel@lists.alioth.debian.org">Bash-completion-devel@lists.alioth.debian.org</a><br>
<a href="http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel" target="_blank">http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel</a><br>
<br>
</div></div></blockquote></div><br></div>