-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheroku-bash-completion.sh
58 lines (49 loc) · 1.5 KB
/
heroku-bash-completion.sh
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
53
54
55
56
57
58
# -*- Mode: shell-script -*-
_heroku_complete() {
COMPREPLY=( $( compgen -W "$1" -- "$cur" ))
}
_heroku_commands() {
# The echo is needed to squash the readline support in the Ruby interpreter that kills bash completion results
# And... since this is slow, we're going to cache the result for a day.
if [[ ! -f ~/.heroku/commands || `cd ~/.heroku && find "commands" -mmin +1440` ]]; then
echo "" | heroku help | grep '#' | awk 'NF > 1 { print $1; }' > ~/.heroku/commands
fi
cat ~/.heroku/commands
}
# TODO: needs to take the naked command into account in some cases
_heroku_sub_commands() {
echo "" | heroku help `echo $cur | cut -d":" -f1` | grep '#' | awk 'NF > 1 { print $1; }'
}
_heroku_sub_commands_regex() {
echo "$(_heroku_commands)" | egrep -v "help|version" | tr "\n" "|"
}
_heroku_remotes() {
git remote -v | sed -n 's/\([a-z]*\).*heroku\.com.*(push)/\1/p'
}
# heroku completion
_heroku() {
local cur prev split=false
COMPREPLY=()
_get_comp_words_by_ref cur prev
_split_longopt && split=true
case $prev in
help|version)
return 0
;;
--remote)
_heroku_complete "$(_heroku_remotes)"
return 0
;;
esac
$split && return 0
if [[ $cur =~ ^(-|--) ]]; then
_heroku_complete "--app --remote"
elif [[ $cur =~ ^($(_heroku_sub_commands_regex)fargle) ]]; then
_heroku_complete "$(_heroku_sub_commands)"
else
_heroku_complete "$(_heroku_commands)"
fi
__ltrim_colon_completions "$cur"
return 0
}
complete -o nospace -F _heroku heroku