Mac Terminal Auto Complete

MacosTerminal

Macos Problem Overview


Usually on a Unix/Linux terminal when you press Tab it will auto-complete until there are several options, and then it will list the options below for you to select. For example:

cd he
helpFolder/ helpMe/ heIsThere/
cd help

With the Mac terminal, it forces you to press it twice to see options. I wondering if it's possible to change that setting to one Tab press?

Macos Solutions


Solution 1 - Macos

  1. Type in terminal nano ~/.inputrc

  2. Paste the following on separate lines

     set completion-ignore-case on
     set show-all-if-ambiguous on
     TAB: menu-complete
    
  3. Hit Control+O to save changes to .inputrc followed by control+X to quit

  4. Open a new Terminal window or tab, or type “login” to open a new session with the rules in effect

  5. Type and hit the tab key

Src: http://osxdaily.com/2012/08/02/improve-tab-completion-in-mac-os-x-terminal/

Solution 2 - Macos

Put this in your ~/.inputrc:

set show-all-if-ambiguous on

You'll need to restart your shell (for example by opening a new terminal window or typing exec /bin/bash).

Solution 3 - Macos

I am adding a new answer because in my case adding the line set show-all-if-ambiguous on was not enough.

I had also to remove the line: TAB: menu-complete.

My complete ~/.inputrc file is the following:

set completion-ignore-case on
set show-all-if-ambiguous on

Solution 4 - Macos

What you want to change is the Bash shell setup. My OS version is 10.11.6 and I use mvim, here just vim or vi,if the ~/.inputrc does not exist, then you need create a new one.

  1. In terminal type vim /.inputrc.

  2. The variable of completion-ignore-case and show-all-if-ambiguous need to be enabled to be ON, this is done by paste those settings in two lines, set completion-ignore-case on and set show-all-if-ambiguous on

  3. Add TAB: menu-complete and write&quit the vim. :wq

  4. Quit the Terminal running, Command+Q.

  5. Start Terminal again and verify the result.

Solution 5 - Macos

Looks like the other comments are for bash whereas MacOs moved already to zsh as default shell. To enable autocompletion (including subcommands), putting the following line in zsh config file (~/.zshrc) works for me:

autoload -Uz compinit && compinit


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1334858View Question on Stackoverflow
Solution 1 - MacosandrewoodleyjrView Answer on Stackoverflow
Solution 2 - Macosrob mayoffView Answer on Stackoverflow
Solution 3 - MacosFrancesco BoiView Answer on Stackoverflow
Solution 4 - MacosMLChrisView Answer on Stackoverflow
Solution 5 - MacosM. KhaledView Answer on Stackoverflow