Turn auto complete on for Mac Terminal

Save a lot of time by turning on autocomplete for your terminal

Thu, 02 Aug 2018

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:

  1. Open up your terminal
  2. Enter the command sudo nano ~/.inputrc and enter your password when prompted
  3. Paste the following commands one at a time

    • set completion-ignore-case on
    • set show-all-if-ambiguous on
    • TAB: menu-complete
  4. Press command key + x to save, then press y to confirm
  5. Open a new Terminal window or tab
  6. Type cd Des and hit the tab key, if everything works as intended it should autofill with cd 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

Loading...
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.