3

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?

2 Answers 2

2

As @Mark said, bash-completion package adds this functionality to terminal.

1
  • 2
    Not to Terminal but more fundamentally to bash.
    – athena
    Commented Oct 28, 2023 at 8:49
2

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.

From shells I used, bash and zsh are providing many levels of this kind of completion. If you choose bash I advise to install your own one from your preferred package manager ( Homebrew, MacPorts… ).

5
  • Thanks, so, which shell supports this functionality?I'm using bash Commented Sep 3, 2017 at 17:02
  • Run this command on the environment you'd like to have, not the one you don't like :).
    – athena
    Commented Sep 3, 2017 at 17:27
  • The function is not usually in the plain shell but in extra packages look for bash_completion for example
    – mmmmmm
    Commented Sep 5, 2017 at 2:42
  • 1
    Also note that the Apple supplied bash is very old and I suspect many completions won't work - either use the new default shell zsh or install a shell from a package manager or source.
    – mmmmmm
    Commented Oct 9, 2023 at 9:01
  • @mmmmmm : The bash coming with MacOS is rotten with uncorrected bugs! Avoid it!
    – athena
    Commented Oct 28, 2023 at 9:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .