1. Overview

When we’re traversing directories in the command line, case sensitivity can be an inconvenience. We tend to remember file names but often forget how they’re capitalized.

Therefore, disabling case sensitivity can reduce errors in auto-completion. This way, our queries will match both upper and lowercase words.

In this tutorial, we’ll look at ways to disable case sensitivity in Bash when using auto-complete. The commands presented here are written with the Bash shell in mind, so they might not work with other shells.

2. Changing Readline Settings

The GNU Readline is a library developed by the GNU project. It provides extra capabilities to command line interfaces. Some Unix shells (e.g., Bash, Zsh) use this library.

In particular, we can use it to customize tab completion.

Depending on where we change the configuration, the scope of our change will be different.

2.1. Using inputrc

We use the inputrc file to configure the Readline library. Therefore, these configurations affect all applications that use the library.

Let’s use the echo command to add settings to inputrc:

$ echo 'set completion-ignore-case on' | sudo tee -a /etc/inputrc

In the example above, we’re using echo to output the configuration.

After, we pipe it to the tee command. We use tee to pipe input to another command or to write to a file. We need it here to perform the pipe operation as sudo.

The -a flag appends to the end of a file.

We use the set command to change shell variables. In this case, we’re changing the value of completion-ignore-case to on.

We’re defining this setting system-wide, but we can also create a user-specific configuration.

Let’s create a new configuration file on the home directory:

$ if [ ! -f ~/.inputrc ]; then echo '$include /etc/inputrc' > ~/.inputrc; fi
$ echo 'set completion-ignore-case on' >> ~/.inputrc

In the first line, we check for the existence of the .inputrc file with the -f flag. If it doesn’t exist, we create a new file with the > operator.

We need to include the system-wide file. There are basic settings that are needed for the normal function of Readline.

Then, we use the >> operator to append the set command to the end of the file.

2.2. Using .bashrc

We use .bashrc to apply configurations to the Bash shell. When we open a shell, it runs the commands in this file.

If we want to disable case sensitivity only in Bash, we can change it in .bashrc.

Let’s change the value of case sensitivity with bind:

$ echo "bind 'set completion-ignore-case on'" >> ~/.bashrc

The bind command changes Readline keybindings and configurations.

3. Conclusion

In this article, we looked at disabling case sensitivity for auto-completion. It can hinder productivity, as it can slow us down.

We saw how GNU Readline is a library responsible for this mechanism. Then, we presented different ways to change its configurations.

Finally, we looked at some commands specifically used for configuring Readline.

Comments are closed on this article!