Bash tab completion expands “~” into “/home/___” when it didn’t before

autocompletebash

Previously, if I typed ~/biTab, before, it would turn into ~/bin. However, today it started turning ~/biTab into /home/username/bin.

I would rather have it the former, but I'm not sure what happened … I did add a script to edit my bash completion but I removed it from my ~./bashrc and restarted the server.

Does anyone know what would cause this to happen? Or how I would change it back?

EDIT So I found out what might cause this…it has to do with /etc/bash_completion and things like that. When I do bind -v, it shows tilde expansion to be off.

So I think if I edit this (kind of like a hack), it will go away. But that doesn't really satisfy anything — how did this change even happen in the first place? I never ran anything as sudo, and after multiple shutdowns and restarts this behavior persists.

Best Answer

You don't mention what distribution you are using (please include that information in your question), but I've seen similar behavior after running updates on my systems.

My best guess is when you ran a system update, or if it ran automatically, the "bash-completion" package was updated which added this behavior. In Red Hat derivatives, you can find package documentation in /usr/share/doc/PACKAGENAME. In my /usr/share/doc/bash-completion-1.3/CHANGES, new changes are listed via a change log format.

Instead of modifying /etc/bash_completion, which could potentially get overwritten at the next package upgrade, you can create ~/.inputrc to disable tilde expansion. I confirmed bash_completion-1.3.6 will honor this on my Fedora 16 box.

set expand-tilde off

EDIT

Your mileage may vary with ~/.inputrc. Bash has functions that may override that behavior depending on what you try to complete (e.g. a program vs a file or directory). This discussion on Super User SE addresses a similar question when autocompleting a vim command. In this case, the original poster solved his issue by adding a custom function to his ~/.bashrc.

Related Question