When I go into any folder via
cd and then press
tab a whole list of options is displayed. How do I make the autocomplete local to the folder?
If you want to see only binaries in the current folder, press
./tab (dot slash tab).
If you want to see all folders in the current folder, press
In your screenshot, pressing
m tab is showing all binaries that start with m found in the path.
In all cases, pressing tab a second time will show all matches if there are more than one.
You're looking for
bash-completion. This post describes how to get it (tl;dr - for an easy install you'll need a package manager like Homebrew or MacPorts) for example:
brew install bash_completion
cd and then Tab the results you get should be limited to folders.
bash-completion covers a wide range of possible completions, but there may be more - check your package manager. For example, on Homebrew try this:
brew search completions
This returns additional completions for macOS tools like
launchctl, virtualisation tools like
vagrant, and many others.
You can create your own completions, for example I use this one to show me only
.png files for a script (
png2icns) I hacked together.
complete -f -X '!*.png' png2icns
However this really isn't necessary for most cases -
bash-completion will cover all the common uses.
For completeness I need to mention that fans of the
zsh shell will no doubt tell you that
zsh's support for completion is far superior to
bash does what I need, albeit with a little help from