A ~/.inputrc for Humans

Last updated on April 14, 2024

~/.inputrc is the user configuration file of GNU readline, which provides customizable command line user interfaces for many important interactive programs, such as Bash and Python interactive shell. However, many of its useful features are disabled by default. In this post, we will walk through a decent ~/.inputrc file to release the power of readline.

tl;dr Copy and paste the code below to your ~/.inputrc file:

$include /etc/inputrc

set colored-stats On
set completion-ignore-case On
set completion-prefix-display-length 3
set mark-symlinked-directories On
set show-all-if-ambiguous On
set show-all-if-unmodified On
set visible-stats On

Here is the explanation.

$include /etc/inputrc: This line carries over site-wide readline configuration to the user configuration. Usually /etc/inputrc includes some goodies.

"\C-p":history-search-backward and "\C-n":history-search-forward: These two lines set Ctrl-P/Ctrl-N to search backward/forward through the history for the string of characters between the start of the current line and the current cursor position.

set colored-stats On: This line sets readline to display possible completions using different colors to indicate their file types. The colors are determined by the environmental variable LS_COLORS, which can be nicely configured.

set completion-ignore-case On: This line sets auto completion to ignore cases.

set completion-prefix-display-length 3: This line sets 3 to be the maximum number of characters to be the common prefix to display for completions. If the common prefix has more than 3 characters, they are replaced by ellipsis. For example, assume we are in a directory with files Screenshot_20170730.png and Screenshot_20170731.png. If using the default option, an auto completion prints Screenshot_20170730.png Screenshot_20170731.png. If this option is set, then the auto completion prints ...0.png ...1.png. However, if the common prefix is very short (fewer or equal to 3 characters), the full file names are still printed. For example, in a directory with files S10.png and S11.png, an auto completion still prints S10.png S11.png. This can be very useful when auto completing in a directory in which a lot of files have a long common prefix, such a camera image directory.

set mark-symlinked-directories On: This line sets every completion which is a symbolic link to a directory to have a slash appended.

set show-all-if-ambiguous On: This line sets the completions to be listed immediately instead of ringing the bell, when the completing word has more than one possible completion.

set show-all-if-unmodified On: This line sets the completions to be listed immediately instead of ringing the bell, when the completing word has more than one possible completion but no partial completion can be made.

set visible-stats On: This lines sets completions to be appended by characters that indicate their file types reported by the stat system call.

Also check out the following links for further improving shell experience:

18 thoughts on “A ~/.inputrc for Humans

  1. Pingback: A ~/.inputrcpara humanos | SCHOLAR

  2. Pingback: Readline crime: exploiting a SUID logic bug - Ciberdefensa

  3. Pingback: Readline crime: exploiting a SUID logic bug | Trail of Bits Blog

  4. Pingback: Suelte Bash para la concha de pescado para obtener hermosos valores predeterminados | Informático 247

  5. Pingback: ショートカットキーの使い方 [Bash] – Site-Builder.wiki

  6. m

    what is the idea of including both “show-all-if-ambiguous” and “show-all-if-unmodified” if the former will override the latter anyways ?

  7. Pingback: Configuração global e do usuário para ambiente shell – Anotações

  8. Pingback: vi モードの使い方 (readline) [Bash] – Site-Builder.wiki

  9. Pingback: Configuring ~/.inputrc | 0ddn1x: tricks with *nix

  10. Pingback: cron.weekly issue #92: RHEL 7.4, Varnish, Exa, Btrfs, sslh, ZFS, inputrc, opensmtpd & more

  11. Pingback: Links 31/7/2017: Linux 4.13 RC3, New MythTV, Mesa 17.2 RC2, Sparky 5.0 Special Editions | Techrights

Leave a Reply

Your email address will not be published. Required fields are marked *