Bash Completion –

by hobbitalastair

Bash completion is a cool bash-specific feature that allows autocompletion of text fields in the CLI.

For instance, ‘pacman -Ss bash-c<tab><tab>’ will automatically complete to ‘pacman -Ss bash-completion’.

Bash is a command shell – a textual interface for launching programs. By typing commands, programs can be launched with options that dictate what they do next. All shells also support scripting – the ability to join multiple commands together to create something more complex, like another command…

An example of this is my immix project. By using the power of shell scripting, I have created a wrapper around an existing program that provides extra functionality, in this case, the ability to automatically sync home directories across computers, but only if the user is logged in and active.

 

Bash completion is driven by completion scripts, which describe how the commands can be completed. By default, bash only completes filenames, but with ‘bash-completion’, it also can complete any supported command. Packages (read: applications) can add their own completion scripts upon installation, even if bash does not include scripts for them by default. On my todo list is writing a bash completion script for my shell scripts…

Bash completion saves me typing. It is therefore cool :).

Well, maybe not. But auto completion does allow more interactive exploration – instead of listing and looking manually, I can just double-tab and a nicely formatted list of my possible choices (albeit without colour) is printed. I like it when things are more interactive :)!

In Arch Linux, bash completion is enabled by default, but only if ‘bash-completion’ is installed.

Advertisements