Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
2  
"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
up vote 10 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
1  
@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
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. – thims Aug 19 '15 at 21:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .