-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompletion
executable file
·157 lines (134 loc) · 2.68 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env bash
# bash completion for Ruby Version Manager (RVM)
__rvm_comp()
{
typeset cur
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=($(compgen -W "$1" -- "$cur"))
return 0
}
__rvm_subcommand()
{
typeset word subcommand c
c=1
while [[ $c -lt $COMP_CWORD ]] ; do
word="${COMP_WORDS[c]}"
for subcommand in $1; do
if [[ "$subcommand" == "$word" ]]; then
echo "$subcommand"
return
fi
done
c=$((++c))
done
}
__rvm_rubies ()
{
echo "$(rvm list strings) default system"
}
__rvm_gemsets ()
{
echo "$(rvm gemset list | \grep -v gemset 2>/dev/null)"
}
__rvm_help_pages ()
{
ls "$rvm_help_path"
}
__rvm_known ()
{
# Strips comments and expands known patterns into each variation
rvm list known | sed -e 's/#.*$//;' \
-e '/^$/d;' \
-e 's/^\[\(.*-\)\]\(.*\)\[\(-.*\)\]$/\1\2\3 \1\2 \2\3 \2/;' \
-e 's/^\[\(.*-\)\]\(.*\)$/\1\2 \2/;' \
-e 's/^\(.*\)\[\(-.*\)\]\[\(-.*\)\]$/\1\2\3 \1\2 \1/;' \
-e 's/^\(.*\)\[\(-.*\)\]$/\1\2 \1/ ' # | tr ' ' "\n" | sort
}
_rvm_commands ()
{
typeset cur
cur=${COMP_WORDS[COMP_CWORD]}
COMMANDS='\
version use reload implode update reset info debug\
install uninstall reinstall remove\
ruby gem rake tests specs monitor gemset\
gemdir srcdir fetch list package notes snapshot\
help'
case "${cur}" in
-*) _rvm_opts ;;
*) __rvm_comp "$COMMANDS $(__rvm_rubies)" ;;
esac
}
_rvm_opts ()
{
RVM_OPTS='\
-h\
--help\
-v\
--version\
-l --level\
--bin\
--gems\
--archive\
--patch
-S\
-e\
-G\
-C\
--configure\
--nice\
--ree-options\
--head\
--rubygems\
--default\
--debug\
--trace\
--force\
--summary\
--latest\
--docs\
--reconfigure
--create'
__rvm_comp "$RVM_OPTS"
}
_rvm_use ()
{
typeset _command
_command="${COMP_WORDS[COMP_CWORD-2]}"
case "${_command}" in
gemset) __rvm_comp "$(__rvm_gemsets)" ;;
*) __rvm_comp "$(__rvm_rubies)" ;;
esac
}
_rvm_gemset ()
{
typeset subcommand subcommands
subcommands="use create"
subcommand="$(__rvm_subcommand "$subcommands")"
if [[ -z "$subcommand" ]]; then
__rvm_comp "$subcommands"
return
fi
}
_rvm_help ()
{
__rvm_comp "$(__rvm_help_pages)"
}
_rvm_install ()
{
__rvm_comp "$(__rvm_known)"
}
_rvm ()
{
typeset prev
prev=${COMP_WORDS[COMP_CWORD-1]}
case "${prev}" in
use) _rvm_use ;;
gemset) _rvm_gemset ;;
help) _rvm_help ;;
install) _rvm_install ;;
*) _rvm_commands ;;
esac
return 0
}
complete -o default -o nospace -F _rvm rvm