Mac OSX 添加 Bash 自动补全支持

安装bash-completion

  1. homebrew安装bash-completion软件包:brew install bash-completion

  2. 把下面内容添加到你的~/.bash_profile:

     if [ -f $(brew --prefix)/etc/bash_completion ]; then
         . $(brew --prefix)/etc/bash_completion
     fi
    
  3. 重启bash,看看是不是很多命令都可以通过tab自动补全了?

添加其它自动补全支持

有些命令的自动补全支持不在bash-completion内,这时候可以手动添加进去,以git为例:

cd /usr/local/opt/bash-completion/etc/bash_completion.d
curl -L -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
brew unlink bash-completion
brew link bash-completion

现在试试看,git 命令是不是已经可以自动补全了?

猜你喜欢

转载自xialluyouyue.iteye.com/blog/2220243