Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Created January 8, 2013 23:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregorynicholas/4489161 to your computer and use it in GitHub Desktop.
Save gregorynicholas/4489161 to your computer and use it in GitHub Desktop.
autocomplete functionality for python library command line interfaces (CLI): Fabric & Paver.
#!/usr/bin/env bash
. paver_autocomplete
. fabric_autocomplete
#!/usr/bin/env bash
_fab()
{
local cur
COMPREPLY=()
# Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
# Build a list of the available tasks from: `fab -l`
local cmds=$(fab -l 2>/dev/null | grep "^ " | awk '{print $1;}')
# Generate possible matches and store them in the
# array variable COMPREPLY
COMPREPLY=($(compgen -W "${cmds}" $cur))
}
# Assign the auto-completion function for our command.
complete -F _fab fab
#!/usr/bin/env bash
_paver()
{
local cur
COMPREPLY=()
# Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
# Build a list of the available tasks from: `paver --help --quiet`
local cmds=$(paver -hq | awk '/^ ([a-zA-Z][a-zA-Z0-9_]+)/ {print $1}')
# Generate possible matches and store them in the
# array variable COMPREPLY
COMPREPLY=($(compgen -W "${cmds}" $cur))
}
# Assign the auto-completion function for our command.
complete -F _paver paver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment