-
Notifications
You must be signed in to change notification settings - Fork 0
/
.fab_bash_completion
52 lines (43 loc) · 1.31 KB
/
.fab_bash_completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#
# Name: fab_bash_completion
# Description: Adds tab-completion to fabfile tasks
# Date: 2009-10-28
#
# Author: Enrico Batista da Luz
# E-mail: [email protected]
# Website: http://ricobl.wordpress.com/
#
# Installation: point to this file from your .bash_profile, like so:
#
# ~/path/to/fab_bash_completion
#
# Mostly adapted from:
#
# http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2
# http://technotales.wordpress.com/2010/01/10/rake-and-capistrano-bash-completion/
# http://www.unix.com/shell-programming-scripting/99282-silent-background-process.html
#
_fab_list () {
# Get the list of available tasks,
# ignoring errors (missing or invalid fabfile)
fab --shortlist 2> /dev/null
}
_fab_completion() {
local cur prev opts cache_file
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cache_file=".fab_completion"
# Read from cache file or get a fresh list
if [ -e "$cache_file" ]; then
opts=`cat $cache_file`
else
opts=`_fab_list`
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
# Always update the local cache in background
(_fab_list > $cache_file &) > /dev/null
return 0
}
complete -F _fab_completion -o default fab