How do I get fink and macports to autocomplete program names when typing commands, as in Ubuntu's apt-get?
For example when I type
sudo port install caand press tab, I want the terminal to autocomplete or show me the available commands.
OS X does not even auto-complete commands after sudo!
1 Answer
bash-completion adds completion for:
- Command names after
sudoandwhich - Macports and Homebrew package names (optional)
- Hostnames in
known_hostsfor commands likessh - Folders on
CDPATH
And so on. You can print a list of completion commands with complete -p and see the source of a function with declare -f.
Installing Homebrew or MacPorts and Bash
First, you have to install Homebrew or MacPorts according to the instructions. Note: Do not install both, as they conflict.
Then, install a newer version of Bash. The built-in Bash in OS X is a little old, and you'll get more completion options with Bash > 4.1, which you can get through
brew install bashor
sudo port install bashdepending on whether you use Homebrew or MacPorts.
Installing bash-completion with Homebrew
To install bash-completion, you have to:
brew install bash-completionAnd add the following to your ~/.bash_profile:
if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion
fiHomebrew currently installs an older version of bash-completion (1.3) that still works with Bash 3.x, but still, using Bash 4.x is recommended.
Installing bash-completion with MacPorts
With MacPorts:
sudo port install bash-completionThen, add to your ~/.bash_profile:
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then . /opt/local/etc/profile.d/bash_completion.sh
fiSee for instructions on how to enable completion for port names.
8