1. Overview

In this tutorial, we’ll talk about the .inputrc file. We’ll cover what it is, what we can use it for, and how it differs from other configuration files such as .bashrc.

For example, there are settings and options in .inputrc that we can also specify in other configuration files. However, based on the file where we specify these settings, they will affect different applications.

2. The .inputrc File and readline

First, let’s start by describing what the .inputrc file is. The file .inputrc is a configuration file in Unix that deals with keyboard mapping and is used as a startup file by readline. Thus, it needs to contain the configuration that concerns this library.

The question now might be: what is readline? The GNU readline library is one that other applications use to interact with a command line. It provides functions such as scrollback, line editing, text cursor movement, clipboard, and tab completion.

readline supports both vi and emacs editing modes, so we can configure (via the .inputrc file) how readline interprets the keyboard inputs. Moreover, the readline library also includes a history functionality. This way, we keep a list of the command lines that we’ve entered previously. We can go back (and even edit) those lines.

Since readline is a library that we can find in many applications, one of its main advantages is we can have the same behavior in all those applications.

Many common applications use readline: shells (like bash), programming language interpreters for languages such as Python, and other interactive tools in the command line. For example, the command line calculator bc and the command-line FTP client lftp also use readline.

With the .inputrc file, we can configure the behavior of all these applications that use readline altogether. It’s convenient to have this for consistent behavior in the applications we use in the command line.

3. Uses and Example Configurations for the .inputrc File

As with many other configuration files, we can find the default .inputrc file in the /etc/ directory:

$ cat /etc/inputrc
# do not bell on tab-completion
#set bell-style none
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
$if mode=emacs
# for linux console and RH/Debian xterm
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[7~": beginning-of-line
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
"\e[1;5C": forward-word
"\e[1;5D": backward-word

However, we may want to expand or modify these options. To customize the options of the /etc/.inputrc file, we need to create a file in our home directory (~/.inputrc). Let’s take a look at an example:

$ cat ~/.inputrc
$include /etc/inputrc
set completion-query-items 150
set completion-ignore-case On
set mark-symlinked-directories On

In our custom ~/.inputrc file, the first line is a directive to include the system-wide readline configuration. We won’t need this first line if we want to start from scratch and not use the default options, but it’s highly recommended to use it.

Then, we’ve defined two shortcuts to search backward and forward in the history functionality. With Ctrl+P, we’ll be able to search backward in the history, and with Ctrl+N, we’ll be able to search forward.

We’ve also requested a limit for completion queries. The default behavior of readline is to display the options in which the current word can end when pressing Tab. With this setting, when there are 150 or more options to complete a word, readline will ask whether we want to display these options or not (instead of directly displaying them).

Finally, we’ve instructed autocompletion to ignore the case and readline to append a slash to symbolic links that point to directories.

4. The .inputrc File Compared to Other Configuration Files

In Linux systems, there are plenty of configuration files that we can use to tweak the behavior of tools. We commonly find .bashrc, .bash-profile, .profile, and also .inputrc.

The main difference between the .inputrc file and these other configuration files is that .inputrc modifies the behavior of the readline library. These settings certainly impact all the applications that use readline.

For example, when we start bashit’ll initialize the history and other settings for the readline library from the .inputrc file and then read other files (such as .bashrc) for settings that are specific to bash.

We can run bash without the readline support to test the settings of bash independently:

$ bash --noediting

Since there is an overlap of functionalities between readline and bash, there’s also an overlap in the settings. We can specify settings in the .inputrc and the .bashrc files that look similar, but they affect different tools. The.inputrc file controls all readline applications, while .bashrc controls only bash.

Let’s consider the length of the command history. Both readline and bash keep a history of the previously run commands. This setting is known as HISTSIZE in bash and as history-size in .inputrc.

If we only provide HISTSIZE, we’ll only change the settings of bash. When we specify a value of history-size, we’ll change the settings of all applications that use readline (including bash!). Finally, if we specify both HISTIZE and history-size, the settings of the readline library will override the setting of bash.

5. Conclusion

In this article, we’ve talked about the .inputrc file and how the readline library and all the applications that rely on this library use the configuration file .inputrc. We’ve seen some examples of commands that we may want in this file. Finally, we’ve discussed the differences between the .inputrc file and other configuration files such as .bashrc.

Notify of
Inline Feedbacks
View all comments