ianmacd 1a7e456891 - fix warnings generated by Ruby 1.8
- fix to work with ri 1.8
2003-09-17 05:39:21 +00:00

52 lines
1.2 KiB
Plaintext

# ri completion for Ruby documentation by Ian Macdonald <ian@caliban.org>
#
# $Id: ri,v 1.2 2003/09/17 07:39:21 ianmacd Exp $
#
ri_get_methods()
{
COMPREPLY=( "$( ri ${classes[@]} | ruby -ane 'if /^-/.../^-/ and \
! /^-/ and ! /^ +(class|module): / then \
print $_.strip.split(/, /).grep(/^[^\[]*$/).join("\n"); \
end' | sort -u )" )
COMPREPLY=( $( compgen $prefix -W '${COMPREPLY[@]}' -- $method ) )
}
_ri()
{
local cur class classes method prefix IFS
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# need to also split on commas
IFS=$', \n\t'
if [[ "$cur" == [A-Z]*#* ]]; then
# we're completing on class#method
class=${cur%#*}
method=${cur#*#}
classes=( $class )
prefix="-P $class#"
ri_get_methods
return 0
fi
if [ "$( ri -v 2>&1 )" = "ri 1.8a" ]; then
classes=( $( ri | ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
if /^ .*[A-Z]/ then print; end; end' ))
else
classes=( $( ri | ruby -ne 'if /^I have/..$stdin.eof then \
if /^ .*[A-Z]/ then print; end; end' ))
fi
if [[ "$cur" == [A-Z]* ]]; then
# we're completing on class
COMPREPLY=( $( compgen -W '${classes[@]}' -- $cur ) )
return 0
fi
# we're completing on methods
method=$cur
ri_get_methods
}
complete -F _ri ri