TAB completion for fabric tasks [on OS X]

Found an excellent bash script on that enables tab completion on the fabric tasks defined in script (in case you don’t know what Fabric is, try Yuji Tomita’s article to get started with it). I just had to modify a little bit to make it work on OS X. I actually wanted to post it in their comments section, but it seems the comments are blocked on that site. So here it goes:

Install bash-completion with Homebrew

brew install bash-completion

You’ll need to add some lines in your ~/.bash_profile file to finish the installation. This will create an etc/bash_completion file under /usr/local directory. Now open the ~/.bash_profile file and add the following lines at the end:

function _fab_complete() {
    local cur
    if [ -f "" ]; then
        COMPREPLY=( $(compgen -W "$(fab -F short -l)" -- ${cur}) )
        return 0
        # no found. Don't do anything.        
        return 1
if [ -f /usr/local/etc/bash_completion ] && ! shopt -oq posix; then
    . /usr/local/etc/bash_completion
    complete -o nospace -F _fab_complete fab

Reload the file with source ~/.bash_profile command, navigate to your project directory where your Fabric script is located and try it out yourself.


3 thoughts on “TAB completion for fabric tasks [on OS X]

  1. @Yuji bash-completion is a Debian package, doesn’t come pre-installed on OS X. The /etc/bash_completion file mentioned in the shell script is non-existent by default. My workaround was to install bash-completion via Homebrew and change the script to look in /usr/local/etc/bash_completion

  2. Hey, thanks for the follow-up. The site is very low traffic, and I go through the comments only from time to time. It is blocked due to previous problems with spam. So it has to be approved manually. I approved it just now 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s