14

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

Gareth
  • 19,080
Johan
  • 5,515

4 Answers4

11

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.

7

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

__expand_tilde_by_ref() {
  return 0
}
mjmt
  • 171
1

A more precise customization would be

_filedir_xspec () { :; }
1

Even more compactly:

_expand() { :; }

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

Gareth
  • 19,080
Joe
  • 19