15.1 C
Texas

Bash Auto Completion

When you’re on Linux, the art of “terminal and commands” is a daily dose. The terminal is a powerful solution for the Linux platform that can perform wonders and tons of tasks. It also provides great versatility and control over the system.

In the case of Bash – the most popular shell for Linux, auto code completion isn’t available by default. Bash can run most of the “sh” scripts without any modification. Code auto-completion is a great feature for reducing your load of typing each and every single command as you type. If you’re interested in the code completion, then Fish shell is the best choice.

Despite default code completion, you can still enjoy the feature, thanks to the great “bash-completion”. This tool will enable the auto-completion feature on Bash shell.

Let’s enjoy “bash-completion” shell right away!

Getting “bash-completion”

- Advertisement -

The “bash-completion” provides all the available pre-built packages for the major Linux distros. Check bash-completion on GitHub.

The following guide will install “bash-completion” from source and it will apply for all the Linux distros.

Grab “bash-completion” –

git clone https://github.com/scop/bash-completion.git

cd bash-completion/

Build the tool –

autoreconf -i

./configure

make

make check

At this stage, you may find out some dependency issue. For passing this stage, “pytest” >= 3.6, pexpect, tcllib and dejagnu.

Install “bash-completion” –

sudo make install

Using “bash-completion”

It’s actually a bash script by itself. Check out the code of “bash-completion” –

bat /etc/profile.d/bash_completion.sh

Bat – a Cat clone https://www.osradar.com/bat-advanced-cat-for-linux/

After the installation is complete, it’s time to enjoy auto code completion. Fire up a terminal –

sudo apt i[TAB]

cat /etc/re[TAB]

You can also set your simple bash completion code. The method follows the following structure –

complete -W ‘<autocompletion_codes>’ <command_name>

Let’s see with an example.

complete -W ‘google.com osradar.com’ host

In the above command, there will be 2 different autocomplete suggestions for “host” (google.com and osradar.com).

Type “host” command –

host [TAB]

host google.com

host osradar.com

Enjoy!

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article