Bash tab completion for Fabric in Ubuntu

15 October 2011

If you going to be using Fabric much (which you will, if you know what’s good for you) then having tab auto-completion of your tasks is a must. There’s already a ticket out for this (targeting┬áversion 1.1) but, in the meantime, I’ve adapted Adam Vanderburg’s OS X completion script for Debian/Ubuntu.

To install, either copy the script into /etc/bash_completion.d/ (if you want it system-wide) or append it to ~/.bash_completion (if you want it for your account only).

have fab && {
_fab_completion()
{
    COMPREPLY=() 
    local cur tasks
    tasks=$(fab --shortlist 2>/dev/null)
    _get_comp_words_by_ref cur
    COMPREPLY=( $(compgen -W "${tasks}" -- ${cur}) )
}
complete -F _fab_completion fab
}

P.S I only modified the original because my version of which doesn’t support the -s switch. You could probably get away just with replacing -s with > /dev/null, but once I start modifying something I can never resist the urge to fiddle.

comments powered by Disqus