~/.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
$include /etc/inputrc "\C-p":history-search-backward "\C-n":history-search-forward 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-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_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
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.