Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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/.

share|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

3 Answers 3

up vote 8 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.

share|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

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

__expand_tilde_by_ref() {
  return 0
}
share|improve this answer

Even more compactly:

_expand() { :; }

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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