|
This type is useful for all those people who use frequently (daily) the terminal or console on GNU / Linux systems. |
Before starting
In case we don't have the bash-completion package installed, we install it:
aptitude install bash-completion
Enable autocomplete on TTYs for all users
We open / etc / profile
nano / etc / profile
We look in / etc / profile for the following lines ...
#enable bash completion in interactive shells
#if [-f / etc / bash_completion] &&! shopt -oq posix; then
#. / etc / bash_completion
#fi
And we replace by:
if ["$ BASH"]; then
if [-f / etc / bash_completion] &&! shopt -oq posix; then
. / etc / bash_completion
fi
fi
The latter will activate bash_completion for all users, including root. But it will only enable it on TTYs, and not on terminal emulators.
We reset the TTY and that's it.
As you can see, we have added an if to the original file, which confirms that the bash_completion runs only when we are in Bash. Without that conditional, GDM will give us the previously mentioned error, since GDM would be calling bash_completion, and for some reason it conflicts with xsession.
Enable autocompletion in terminal emulators for all users
We open /etc/bash.bashrc
# nano /etc/bash.bashrc
We look in /etc/bash.bashrc for the following lines ...
#enable bash completion in interactive shells
#if [-f / etc / bash_completion] &&! shopt -oq posix; then
#. / etc / bash_completion
#fi
... And we remove the "#" (we uncomment them), looking like this:
#enable bash completion in interactive shells
if [-f / etc / bash_completion] &&! shopt -oq posix; then
. / etc / bash_completion
fi
The latter will activate bash_completion for all users, including root. But it will only enable it on terminal emulators, and not on TTYs.
We restart any terminal and the changes will take effect.
Enable autocompletion in terminal emulators for one user only
We must create (or edit, if it exists) the file ~ / .bashrc.
nano ~ / .bashrc
We add (or search if they do not exist, but commented, as is done in /etc/bash.bashrc) so that it looks like this:
#enable bash completion in interactive shells
if [-f / etc / bash_completion] &&! shopt -oq posix; then
. / etc / bash_completion
fi
- If file we create it, we simply add these lines.
- If these lines exist but are not present, we add them to the end of the file.
- If it exists and these lines are, we simply uncomment them.
We restart the console and the changes will take effect.
Enable autocomplete when desired
We simply have to run bash_completion at the moment we want to use it. It will be deactivated once we end the session in the terminal (with the exit command) or close the terminal that we are using if we are in a graphical environment. To run it whenever we want, we do:
. / etc / bash_completion
Source: the 98 notebook