March 20th, 2012 by exhuma.twn

Here’s a small bash function to provide TAB-completion for fabric tasks.

Simply add the following to your ~/.bashrc

You may already have a block like if [ -f /etc/bash_completion ]... in that case, simply add the extra line into that block.

# # Bash completion for fabric # function _fab_complete() { local cur if [[ -f "fabfile.py" || -d "fabfile" ]]; then cur="${COMP_WORDS[COMP_CWORD]}" COMPREPLY=( $(compgen -W "$(fab -F short -l)" -- ${cur}) ) return 0 else # no fabfile.py found. Don't do anything. return 1 fi } # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion complete -o nospace -F _fab_complete fab fi

Have fun