Case-insensitive Tab Completion in Bash

In Ubuntu, there are several default folders created when you added a new user, listing as shown. All this while, whenever I need to access one of these folders, I always need to capitalize the first character to trigger the tab completion.
$ ls
Desktop/  Documents/  Downloads/  Music/  Pictures/  Public/  Templates/  Videos/  examples.desktop

That day, while setting up another Ubuntu installation, it dawned on me to check whether case-insensitive works for tab completion in Bash? As usual, Google and AskUbuntu did not fail me. Yes, we can do that in Bash. So many years of using Ubuntu and it never occurs for me to raise such question?

To enable case-insensitive, just set completion-ignore-case for the Readline init file, .inputrc.
$ if [ ! -a ~/.inputrc ]; then echo "\$include /etc/inputrc" > ~/.inputrc; fi
$ echo "set completion-ignore-case On" >> ~/.inputrc

While we're looking into this, there are also another option, completion-map-case, which treats hypens ('-') and underscores ('_') as equivalent.

The final .inputrc file should look like below.
$include /etc/inputrc
set completion-ignore-case on
set mark-symlinked-directories on

No comments:

Post a Comment