Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tweaking Bash 'cd' and TAB completion to recognize spelling mistakes

Tags:

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?

like image 240
Vihaan Verma Avatar asked Apr 05 '12 07:04

Vihaan Verma


1 Answers

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.

like image 197
ArjunShankar Avatar answered Oct 12 '22 02:10

ArjunShankar