Thursday, September 13, 2012

Bash Completion for Mac OS X

I've been using my Mac more often lately, and I realized I was really missing the fancy bash completion features that Ubuntu has. Turns out, it's pretty easy to enable on Mac with Homebrew:

brew install bash-completion

Then, as usual, homebrew tells you exactly what you have to do. Just add this to .bashrc:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

Now you get fancy completion. Here's me hitting tab twice with a git command:

$ git checkout rdiankov
rdiankov-master          rdiankov/animation       rdiankov/animation2
rdiankov/collada15spec   rdiankov/master          rdiankov/pypy

Awesome.

10 comments:

  1. I have Git installed from instead of from Homebrew. And I get its Bash completion by:

    . /usr/local/git/contrib/completion/git-completion.bash

    Looks like Homebrew packages Git's Bash completion in git-extras rather than bash-completion.

    ReplyDelete
    Replies
    1. I think something got cut off there. Git installed from where?

      Delete
  2. I installed bash-completion with brew to my 10.8.4, but tab still didn't bring results with git. I wondered if this was because I was using Apple provided git and installed newer git with brew. After installation it said:

    Bash completion has been installed to:
    /usr/local/etc/bash_completion.d

    Now bash completion works with git too. I think this was what Matt was saying. :) Except I didn't need to install git-extras, just "brew install git" did the trick.

    Thanks for the tip. Your post was first link on google results. :)

    ReplyDelete
  3. It would be better to add this to ~/.bash_profile, rather than .bashrc (since that runs every single time a new shell/window gets opened)

    ReplyDelete
  4. Thank you so much. this has officially made my lazy life so much better. +1

    ReplyDelete
  5. You can also use zshrc from oh my zsh and it will get you autocomplete and git branch name in the prompt...very nice

    ReplyDelete
  6. You can also use zshrc from oh my zsh and it will get you autocomplete and git branch name in the prompt...very nice

    ReplyDelete
  7. Above all the points to consider to choose my new domain time. I get it clear idea website design topic. It's really helpful to improve my web hosting knowledge IOS Applications Development

    ReplyDelete