Case insensitive tab completion in Bash

Solution 1:

Update the text in /etc/inputrc to include

set completion-ignore-case on

Then use ^X ^R to reload the configuration.

Solution 2:

Restructured with the benefit of hindsight to contrast the pros and cons of using [.]inputrc vs. .bash_profile.
Tip of the hat to underscore_d for his help.

Note: Command-line editing in Bash is provided by the Readline library; customizing it is non-trivial, but well worth learning; its features include the ability to define custom keyboard shortcuts for inserting predefined snippets of text - see Command Line Editing in the Bash Reference Manual

To persistently make tab-completion case-insensitive in Bash:


Option A: If you either already have:

  • an /etc/inputrc file (applies system-wide, modification requires sudo)
  • and/or a ~/.inputrc file (user-specific)

    and/or

you're planning to customize the readline library extensively and/or want to make customizations effective for scripts too when they call read -e:

Add line

set completion-ignore-case on

to either file, depending on whether you want the setting to be effective for all users or the current user (create the file, if necessary).

A related command that makes completion of file and directory names easier is:

set show-all-if-ambiguous on

This makes it unnecessary to press Tab twice when there is more than one match.


Option B: Alternatively, you may add Readline commands to your user-specific ~/.bash_profile file on OS X (or ~/.bashrc on Linux), by passing them as a single argument to the bind builtin:

bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"

Note that bind commands in ~/.bash_profile / ~/.bashrc take precedence over equivalent commands in either /etc/inputrc or ~/.inputrc.

As implied above, Readline configuration defined this way will not take effect in scripts that call read -e to activate Readline support for reading user input.

Solution 3:

To avoid changing configuration for all users and to avoid root permissions use the following:

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

Then re-login or reload ~/.inputrc