up vote 7 down vote favorite
2
share [g+] share [fb]

I use the Tab key a lot when I use the shell (bash).

But I'm getting annoyed that ~ always gets expanded to /home/"user". I don't think it's always been like this; is there any way to stop this behaviour?

An example:

  1. cj@zap:~$ ls ~/
  2. Press Tab
  3. cj@zap:~$ ls /home/cj/

I would like to continue to have ~/ and not end up with /home/cj/.

link|improve this question

1  
"I don't think it always has been like this." - Programmable completion overrides the readline setting set expand-tilde off (default or set in ~/.inputrc). – Dennis Williamson Jan 14 '10 at 9:45
"bind -v | grep tilde" returns "set expand-tilde off" ... so I don't think it will help. – Johan Jan 14 '10 at 12:30
feedback

3 Answers

up vote 6 down vote accepted

Disabling tilde expansion is quick and painless. Open up ~/.bashrc and insert this:

_expand()
{
    return 0;
}

This will override the expand function from /etc/bash_completion. I'd recommend commenting on what it does above the function in case you want the expansion back in the future. Changes will take effect in a new instance.

link|improve this answer
Thanks___________ :) – Johan Jan 14 '10 at 8:01
though _expand(){ true; } is shorter :) – tig Dec 23 '10 at 18:21
would it not be _expand(){ false; }? @tig – John T Dec 23 '10 at 20:07
@John: no it should be true. true returns successful result and successful result is 0, so return 0 is equal to true in exit status, and return 1 is equal to false. just try true; echo $? and false; echo $?. – tig Dec 24 '10 at 7:40
@tig too much programming has confused me... codepad.org/Frb3RyAN Similarly, you find this in lots of code (see top): cs.nthu.edu.tw/~tingting/DS_mid_solution.pdf I would assume it's switched up in the GNU tools to indicate a more realistic meaning, i.e. "True, the program ran successfully" or "false -- the program ran incorrectly". – John T Dec 25 '10 at 0:48
show 2 more comments
feedback

With newer bash_completion it seems you also need to override __expand_tilde_by_ref:

__expand_tilde_by_ref() {
  return 0
}
link|improve this answer
feedback

Even more compactly:

_expand() { :; }

...as ":" is a shell built-in equivalent to "true" :-)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.