Preventing bash tab completion of an environment variable with a FS path value from removing the environment variable name
Friends,
I am using GNU bash as my shell on Linux:
$ bash --version
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$
It acts very strangely when I am setting an environment variable with a FS path as its value.
Say I want to add /opt/database/bin to the front of PATH.
I start by typing in:
$ export PATH=/o
Then I press the tab key on my keyboard.
But instead of completing the path to /opt, it deletes the PATH= part! Instead, I get:
$ export /opt/
That is, of course, extremely useless to me and very aggravating! I am then required to add in the environment variable name manually, which is not at all what I wish to be doing!
I wanted it to complete it to this:
$ export PATH=/opt/
Then I can complete the rest of the path using minimal typing and the tab key.
Is there any way that I can get it to not delete the environment variable, and to act in a sensible way that helps make me productive to the max?
Solution 1:
Try disabling Bash-Completion.
Your PATH
completion works for me, however, on systems using Bash-Completion. You might try un-installing and re-installing it to see if it works. I find the functionality it provides too useful to give up.
Solution 2:
disabling Bash-Completion altogether has probably been an overkill. It is a very useful and productive feature.
The breakage such as you describe is usually caused by specific bash completion configuration scripts that lie in /etc/bash_completion.d/
, installed by third party .deb
packages.
I had the exact same problem on Ubuntu, and in my case the culprit turned out to be the /etc/bash_completion.d/npm
script installed by the npm
Debian package (containing the package manager for Node.js).
I've just moved the npm
script out of /etc/bash_completion.d/
- problem solved, and useful Bash Completion functionality preserved.