141
51
Is there any way to make Bash tab complete case insensitively?
$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.
I am using Mac OS X 10.6
141
51
Is there any way to make Bash tab complete case insensitively?
$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.
I am using Mac OS X 10.6
172
Update the text in /etc/inputrc
to include
set completion-ignore-case on
Then use ^X ^R
to reload the configuration.
114
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:
/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.
1Great point re show-all-if-ambiguous
. However, since you say "as an alternative", is there actually any benefit to doing this via bind
, when the inputrc
files seem to make that unncessary? – underscore_d – 2015-10-18T21:07:07.300
1@underscore_d: Good question; please see my updated answer. – mklement0 – 2015-10-18T21:25:34.613
1Cool, thanks! On Debian 8.2 I had neither inputrc
, but I happily created ~/.inputrc
& added these, plus other really useful directives. I guess we're assuming all readers know that /etc/inputrc
affects other users (unless the latter override the affected settings)? Just while we're mentioning caveats ;) – underscore_d – 2015-10-18T22:04:41.483
1I think that covers everything - thanks for your efforts making a great answer even better! – underscore_d – 2015-10-19T08:41:14.603
11show-all-if-ambiguous is so nice! I often wondered why they made me tab twice to perform that action. thousands of keystrokes saved in my future! thanks! – user34112 – 2013-09-24T07:16:21.317
4
Awesome, it even works for cd
commands. Which solves this question and will be saving me thousands of keystrokes too. :)
1
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
1So that's what msysgit has but MSYS2 lacks! Here I was trying to find it in e.g. /etc/profile ... – SamB – 2015-08-31T18:01:16.117
Writing this to ~/.inputrc breaks the ctrl key functionality. Or am I the only one with this problem? – Exocom – 2016-10-05T11:55:44.003
if not successful with reload the configuration, can just restart bash – Liker777 – 2018-03-25T19:46:50.000
I'm on macOS and new to bash. How exactly does one "Update the text in /etc/inputrc" ? – StatsScared – 2020-01-04T03:27:17.423
14@DennisWilliamson: you can do
bind "set completion-ignore-case on"
from the command line; for, I believe, that terminal session only – Clay Bridges – 2011-10-04T19:45:56.71031"as well" -
/etc/inputrc
or~/.inputrc
or a file designated byINPUTRC
are the only places it can go. Entering that at a Bash prompt won't work. – Paused until further notice. – 2010-01-01T21:11:39.013whoops! you're right :) – John T – 2010-01-01T21:18:06.423
10
^X ^R
to reloadinputrc
– user1686 – 2010-01-02T09:37:24.957