|
1 | 1 | # ri completion for Ruby documentation -*- shell-script -*-
|
2 | 2 | # by Ian Macdonald <[email protected]>
|
3 | 3 |
|
4 |
| -_comp_cmd_ri__methods() |
| 4 | +# @var[in] ri_version |
| 5 | +# @var[in] prefix |
| 6 | +# @var[in] classes |
| 7 | +_comp_cmd_ri__compgen_methods() |
5 | 8 | {
|
6 |
| - local regex |
| 9 | + local _regex |
7 | 10 | local IFS=$' \t\n' # needed for ${classes[@]+"${classes[@]}"} in bash-5.2
|
8 | 11 |
|
| 12 | + local _methods |
9 | 13 | if [[ $ri_version == integrated ]]; then
|
10 | 14 | if [[ ! $separator ]]; then
|
11 |
| - regex="(Instance|Class)" |
| 15 | + _regex="(Instance|Class)" |
12 | 16 | elif [[ $separator == "#" ]]; then
|
13 |
| - regex=Instance |
| 17 | + _regex=Instance |
14 | 18 | else
|
15 |
| - regex=Class |
| 19 | + _regex=Class |
16 | 20 | fi
|
17 | 21 |
|
18 |
| - _comp_split -la COMPREPLY \ |
| 22 | + _comp_split -la _methods \ |
19 | 23 | "$(ri ${classes[@]+"${classes[@]}"} 2>/dev/null | ruby -ane \
|
20 |
| - 'if /^'"$regex"' methods:/.../^------------------|^$/ and \ |
| 24 | + 'if /^'"$_regex"' methods:/.../^------------------|^$/ and \ |
21 | 25 | /^ / then print $_.split(/, |,$/).grep(/^[^\[]*$/).join("\n"); \
|
22 | 26 | end' 2>/dev/null | sort -u)"
|
23 | 27 | else
|
24 | 28 | # older versions of ri didn't distinguish between class/module and
|
25 | 29 | # instance methods
|
26 |
| - _comp_split -la COMPREPLY \ |
| 30 | + _comp_split -la _methods \ |
27 | 31 | "$(ruby -W0 "$ri_path" ${classes[@]+"${classes[@]}"} 2>/dev/null | ruby -ane \
|
28 | 32 | 'if /^-/.../^-/ and ! /^-/ and ! /^ +(class|module): / then \
|
29 | 33 | print $_.split(/, |,$| +/).grep(/^[^\[]*$/).join("\n"); \
|
30 | 34 | end' | sort -u)"
|
31 |
| - fi |
32 |
| - ((${#COMPREPLY[@]})) && |
33 |
| - _comp_compgen -c "$method" -- -P "$prefix" -W '"${COMPREPLY[@]}"' |
| 35 | + fi && |
| 36 | + _comp_compgen -- -P "$prefix" -W '"${_methods[@]}"' |
34 | 37 | }
|
35 | 38 |
|
36 | 39 | # needs at least Ruby 1.8.0 in order to use -W0
|
@@ -87,7 +90,7 @@ _comp_cmd_ri()
|
87 | 90 | method=${cur#*"$separator"}
|
88 | 91 | classes=($class)
|
89 | 92 | prefix=$class$separator
|
90 |
| - _comp_cmd_ri__methods |
| 93 | + _comp_compgen -c "$method" -i ri methods |
91 | 94 | return
|
92 | 95 | fi
|
93 | 96 |
|
@@ -117,8 +120,7 @@ _comp_cmd_ri()
|
117 | 120 | fi
|
118 | 121 |
|
119 | 122 | # we're completing on methods
|
120 |
| - method=$cur |
121 |
| - _comp_cmd_ri__methods |
| 123 | + _comp_cmd_ri__compgen_methods |
122 | 124 | } &&
|
123 | 125 | complete -F _comp_cmd_ri ri
|
124 | 126 |
|
|
0 commit comments