1
# ri completion for Ruby documentation by Ian Macdonald <ian@caliban.org>
8
if [ "$ri_version" = integrated ]; then
9
if [ -z "$separator" ]; then
10
regex="(Instance|Class)"
11
elif [ "$separator" = "#" ]; then
17
COMPREPLY=( ${COMPREPLY[@]} \
18
"$( ri ${classes[@]} 2>/dev/null | ruby -ane \
19
'if /^'"$regex"' methods:/.../^------------------|^$/ and \
20
/^ / then print $_.split(/, |,$/).grep(/^[^\[]*$/).join("\n"); \
23
# older versions of ri didn't distinguish between class/module and
25
COMPREPLY=( ${COMPREPLY[@]} \
26
"$( ruby -W0 $ri_path ${classes[@]} | ruby -ane \
27
'if /^-/.../^-/ and ! /^-/ and ! /^ +(class|module): / then \
28
print $_.split(/, |,$| +/).grep(/^[^\[]*$/).join("\n"); \
31
COMPREPLY=( $( compgen $prefix -W '${COMPREPLY[@]}' -- $method ) )
34
# needs at least Ruby 1.8.0 in order to use -W0
37
local cur class method prefix ri_path ri_version separator IFS
41
_get_comp_words_by_ref cur
44
# which version of ri are we using?
45
# -W0 is required here to stop warnings from older versions of ri
46
# from being captured when used with Ruby 1.8.1 and later
47
ri_version="$(ruby -W0 $ri_path -v 2>&1)" || ri_version=integrated
48
[ "$ri_version" != "${ri_version%200*}" ] && ri_version=integrated
50
# need to also split on commas
52
if [[ "$cur" == [A-Z]*[#.]* ]]; then
53
[[ "$cur" == *#* ]] && separator=# || separator=.
54
# we're completing on class and method
55
class=${cur%$separator*}
56
method=${cur#*$separator}
58
prefix="-P $class$separator"
63
if [ "$ri_version" = integrated ]; then
64
# integrated ri from Ruby 1.9
65
classes=( $( ri -c | ruby -ne 'if /^\s*$/..$stdin.eof then \
66
if /, [A-Z]+/ then print; end; end' ) )
67
elif [ "$ri_version" = "ri 1.8a" ]; then
68
classes=( $( ruby -W0 $ri_path | \
69
ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
70
if /^ .*[A-Z]/ then print; end; end' ))
72
classes=( $( ruby -W0 $ri_path | \
73
ruby -ne 'if /^I have/..$stdin.eof then \
74
if /^ .*[A-Z]/ then print; end; end' ))
77
COMPREPLY=( $( compgen -W '${classes[@]}' -- "$cur" ) )
78
if [[ "$cur" == [A-Z]* ]]; then
79
# we're completing on class or module alone
83
# we're completing on methods
93
# sh-indent-comment: t
94
# indent-tabs-mode: nil
96
# ex: ts=4 sw=4 et filetype=sh