Turn auto complete on for Mac Terminal
Save a lot of time by turning on autocomplete for your terminal
One of the most useful features when navigating through files and folders in the terminal is autocomplete. Autocomplete will fill in the rest of your command with available options when you press the tab
key while typing. This feature will speed up your workflow completing a lot of commands for you. It comes immensely useful when the folder name contains space and couple of words.
Both Linux and Windows OS have this feature turned on by default, unfortunately in OS X, this feature is turned off by default.
To turn on autocomplete in Mac Terminal do the following steps:
- Open up your terminal
- Enter the command
sudo nano ~/.inputrc
and enter your password when prompted -
Paste the following commands one at a time
set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete
- Press
command key + x
to save, then pressy
to confirm - Open a new Terminal window or tab
- Type
cd Des
and hit the tab key, if everything works as intended it should autofill withcd Desktop/
For those of you who are interesting in what each command does, I will explain it in further detail below. The command sudo nano ~/.inputrc
has 3 parts to it. sudo
gives us full access to a file, think of it being similar to running a program/file in windows as an administrator. The command is from Linux/Unix systems and more info can be found here. The next portion is nano
, which is just a simple command line text editor. This will allow us to edit the final part of our command, .inputrc
. The .inputrc
file is just a configuration file that holds some customization variables for our terminal.
The final portion, the settings we change. The completion-ignore-case
is fairly straightforward, when it is set to on it will ignore letting casing for autocompletions. What this means it that both des
and Des
will result in autocompleting to Desktop/
. show-all-if-ambiguous
is a little more interesting, here is the description of the setting from its man page:
This alters the default behavior of the completion functions. If set to ‘on’, words which have more than one possible completion cause the matches to be listed immediately instead of ringing the bell. The default value is ‘off’.
This means that the word will be partially completed up to the point where there is ambiguity AND will print all completions in one step. Here is an example from stack overflow that explains it. The original post can be found here
Say we have two files named abcd.txt
and abce.txt
typing
ls a
will show(don’t mind my bad formatting, this will show up all one line after another as soon as tab is pressed)
ls a
abcd.txt abce.txt
ls abcd