diff --git a/contrib/ri b/contrib/ri index 80ee6e5e..8a3599de 100644 --- a/contrib/ri +++ b/contrib/ri @@ -1,4 +1,32 @@ -_path ${classes[@]} | ruby -ane 'if /^-/.../^-/ and \ +# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*- +# ex: ts=8 sw=8 noet filetype=sh +# +# ri completion for Ruby documentation by Ian Macdonald + +have ri && { +ri_get_methods() +{ + local regex + + if [ "$ri_version" = integrated ]; then + if [ -z "$separator" ]; then + regex="(Instance|Class)" + elif [ "$separator" = "#" ]; then + regex=Instance + else + regex=Class + fi + + COMPREPLY=( ${COMPREPLY[@]} \ + "$( ri ${classes[@]} 2>/dev/null | \ + ruby -ane 'if /^'"$regex"' methods:/.../^------------------|^$/ and \ + /^ / then print $_.split(/, |,$/).grep(/^[^\[]*$/).join("\n"); \ + end' | sort -u )" ) + else + # older versions of ri didn't distinguish between class/module and + # instance methods + COMPREPLY=( ${COMPREPLY[@]} \ + "$( ruby -W0 $ri_path ${classes[@]} | ruby -ane 'if /^-/.../^-/ and \ ! /^-/ and ! /^ +(class|module): / then \ print $_.split(/, |,$| +/).grep(/^[^\[]*$/).join("\n"); \ end' | sort -u )" )