diff options
Diffstat (limited to 'completions/ri')
-rw-r--r-- | completions/ri | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/completions/ri b/completions/ri index be66d98f..70756325 100644 --- a/completions/ri +++ b/completions/ri @@ -1,6 +1,6 @@ -# ri completion for Ruby documentation by Ian Macdonald <ian@caliban.org> +# ri completion for Ruby documentation -*- shell-script -*- +# by Ian Macdonald <ian@caliban.org> -have ri && { ri_get_methods() { local regex @@ -14,15 +14,15 @@ ri_get_methods() regex=Class fi - COMPREPLY=( ${COMPREPLY[@]} \ + COMPREPLY+=( \ "$( ri ${classes[@]} 2>/dev/null | ruby -ane \ 'if /^'"$regex"' methods:/.../^------------------|^$/ and \ /^ / then print $_.split(/, |,$/).grep(/^[^\[]*$/).join("\n"); \ - end' | sort -u )" ) + end' 2>/dev/null | sort -u )" ) else # older versions of ri didn't distinguish between class/module and # instance methods - COMPREPLY=( ${COMPREPLY[@]} \ + COMPREPLY+=( \ "$( ruby -W0 $ri_path ${classes[@]} | ruby -ane \ 'if /^-/.../^-/ and ! /^-/ and ! /^ +(class|module): / then \ print $_.split(/, |,$| +/).grep(/^[^\[]*$/).join("\n"); \ @@ -34,11 +34,11 @@ ri_get_methods() # needs at least Ruby 1.8.0 in order to use -W0 _ri() { - local cur class method prefix ri_path ri_version separator IFS - local -a classes + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur + local class method prefix ri_path ri_version separator IFS + local -a classes ri_path=$(type -p ri) # which version of ri are we using? @@ -62,8 +62,8 @@ _ri() if [ "$ri_version" = integrated ]; then # integrated ri from Ruby 1.9 - classes=( $( ri -c | ruby -ne 'if /^\s*$/..$stdin.eof then \ - if /, [A-Z]+/ then print; end; end' ) ) + classes=( $( ri -c 2>/dev/null | ruby -ne 'if /^\s*$/..$stdin.eof then \ + if /, [A-Z]+/ then print; end; end' 2>/dev/null ) ) elif [ "$ri_version" = "ri 1.8a" ]; then classes=( $( ruby -W0 $ri_path | \ ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \ @@ -83,14 +83,7 @@ _ri() # we're completing on methods method=$cur ri_get_methods -} +} && complete -F _ri ri -} -# Local variables: -# mode: shell-script -# sh-basic-offset: 4 -# sh-indent-comment: t -# indent-tabs-mode: nil -# End: # ex: ts=4 sw=4 et filetype=sh |