Bash completion is a feature that provides command-line autocompletion for bash commands, options, and file names, making terminal usage faster and more efficient. It’s particularly useful for administrators managing servers, such as those hosted on a VPS server. In this guide, we will walk you through how to add bash completion on Debian.
Step 1: Update Your System
Before installing bash completion, it's a good idea to ensure your Debian system is up to date. Run the following commands to update your package list and install any available updates:
sudo apt update && sudo apt upgrade -y
Step 2: Install Bash Completion
Bash completion may not be installed by default on your system. To install it, simply run the following command:
sudo apt install bash-completion -y
Once installed, bash completion should be automatically enabled. However, you can ensure that it's loaded by editing the .bashrc
file in your home directory.
Step 3: Enable Bash Completion
To enable bash completion, open your .bashrc
file:
nano ~/.bashrc
Look for the following lines, and if they are commented out (starting with a #
), remove the #
to uncomment them:
# enable bash completion in interactive shells
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
Save the file and exit the text editor. To apply the changes, either log out and log back in, or run the following command:
source ~/.bashrc
Step 4: Test Bash Completion
Now that bash completion is installed and enabled, you can test it by typing the beginning of a command and pressing Tab
to see if the shell autocompletes the command or shows suggestions. For example, type sudo ap
and press Tab
—it should complete the command to sudo apt
.
Step 5: Add Bash Completion for Specific Programs
Some programs and scripts support bash completion but do not enable it by default. You can manually add bash completion for specific commands by downloading the completion script and sourcing it in your .bashrc
file.
For example, to enable git completion, download the completion script and source it:
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bashrc
source ~/.bashrc
You can do this for many other programs that support custom bash completions.
Running Bash Completion on a VPS Server
When managing a VPS server, having bash completion enabled significantly speeds up administrative tasks, such as managing packages, configuring services, or running scripts. It reduces typing errors and helps administrators navigate commands more efficiently on their VPS environment.
Looking for a Reliable VPS Solution?
If you're looking for a reliable and scalable VPS server to run your projects or manage server tasks efficiently, consider using WindowsVPS. With WindowsVPS, you get high-performance VPS hosting with full control over your server, making it perfect for developers, sysadmins, and businesses alike.