21

I was looking for a tweak to the cd command so that it recognizes spelling mistakes of directories and auto complete similar directory names.

Right now, I have settings that recognize the spelling mistakes of directory but does not auto complete them.

For directory spelling mistake correction I have this code in ~/.bashrc:

shopt -s cdspell

Now it works in the following manner, suppose I have a directory called "trash"

vickey@home:~$ cd tras
trash
vickey@home:~/trash$ cd ..
vickey@home:~$ cd trasx
trash
vickey@home:~/trash$ pwd
/home/vickey/trash
vickey@home:~/trash$ 


vickey@home:~$ cd Trash
trash
vickey@home:~/trash$ pwd
/home/vickey/trash

But the problem I have is suppose I make a directory called Temp and do something like

vickey@home:~$ mkdir Temp
vickey@home:~$ cd temp
Temp
vickey@home:~/Temp$ cd ..
vickey@home:~$ cd te #and tab here
test/   textin/ 

it does not show Temp as an option. Is there anyway to make auto completion case insensitive?

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126

1 Answers1

27

Completion is a feature of readline.

You can enable case insensitive completion either by:

1) Adding to your ~/.bashrc:

bind 'set completion-ignore-case on'

OR

2) Adding to your /etc/inputrc:

set completion-ignore-case on

Notes:

  • /etc/inputrc, as @mak comments, effects all shells that use readline, and not just bash.

  • This will make all completions case insensitive.

ArjunShankar
  • 23,020
  • 5
  • 61
  • 83
  • 2
    `inputrc` is used by shells that make use of `readline` like `bash`, `dash` and `zsh` (as opposed to `ksh`, `tcsh`, etc.). If you want to affect the behaviour of all your shells (not only `bash`), you need to edit `inputrc`. You can also locally edit `~/.inputrc` so you don't have to make changes in the global `/etc/inputrc`. .Otherwise, great answer! – mak May 25 '15 at 23:58
  • echo "set completion-ignore-case on" | sudo tee -a /etc/inputrc – Morten Apr 01 '19 at 19:25