MacOS – How to get a terminal general auto-complete function

auto-completecommand linemacosterminal

I'm new in macOS and I'm using macOS Sierra,

In my Ubuntu and other Linux-based system, terminal has an auto-complete that helps to complete commands and their options.

For example for wget and other commands, in additional to command completion, after pressing Tab 2 times, it lists all command options (if any), or in sudo w it list all commands start with w

Ubuntu terminal auto-compelete

But on my Mac, it just complete first commands and don't help for options or second part of command like whoami in sudo whoami,

I mean it don't show a list of all command that start with who after pressing Tab 2 times in sudo who

[2]

I found some Scripts for git options at https://github.com/git/git/tree/master/contrib/completion/ , but I want something that do this for all commands and applications.

Is there any solution for that?

Best Answer

The completion function is neither coming from any Terminal application or the OS on which you work: MacOS X, Linux…

This function is provided by your shell. To check which one is providing you the completion function you like, just get which shell you are using on Linux with:

echo ${SHELL}

Then change your login shell on MacOS X with:

chsh -s /bin/my_preferred_shell

to use the one which is performing the completion function you want.

Check that this shell exists and is executable, and read the documentation of chsh:

ls -ld /bin/my_preferred_shell

man chsh

To test it without risk, don't restart your session, just open a new Terminal. In case of error, you will be able to run chsh once more.