summaryrefslogtreecommitdiff
path: root/completions/ri
diff options
context:
space:
mode:
Diffstat (limited to 'completions/ri')
-rw-r--r--completions/ri43
1 files changed, 37 insertions, 6 deletions
diff --git a/completions/ri b/completions/ri
index 62a9b709..16e44664 100644
--- a/completions/ri
+++ b/completions/ri
@@ -34,10 +34,36 @@ _ri_get_methods()
# needs at least Ruby 1.8.0 in order to use -W0
_ri()
{
- local cur prev words cword
- _init_completion || return
+ local cur prev words cword split
+ _init_completion -s -n : || return
- local class method prefix ri_path ri_version separator IFS
+ case $prev in
+ -h|--help|-w|--width)
+ return
+ ;;
+ -f|--format)
+ COMPREPLY=( $( compgen -W 'ansi bs html rdoc' -- "$cur" ) )
+ return
+ ;;
+ -d|--doc-dir)
+ _filedir -d
+ return
+ ;;
+ --dump)
+ _filedir ri
+ return
+ ;;
+ esac
+
+ $split && return
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
+ [[ $COMPREPLY == *= ]] && compopt -o nospace
+ return
+ fi
+
+ local class method prefix ri_path ri_version ri_major separator IFS
local -a classes
ri_path=$(type -p ri)
@@ -46,6 +72,7 @@ _ri()
# from being captured when used with Ruby 1.8.1 and later
ri_version="$(ruby -W0 $ri_path -v 2>&1)" || ri_version=integrated
[[ $ri_version != ${ri_version%200*} ]] && ri_version=integrated
+ [[ $ri_version =~ ri[[:space:]]v?([0-9]+) ]] && ri_major=${BASH_REMATCH[1]}
# need to also split on commas
IFS=$', \n\t'
@@ -57,13 +84,15 @@ _ri()
classes=( $class )
prefix="-P $class$separator"
_ri_get_methods
- return 0
+ return
fi
if [[ $ri_version == integrated ]]; then
# integrated ri from Ruby 1.9
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_major && $ri_major -ge 3 ]]; then
+ classes=( $( ri -l 2>/dev/null ) )
elif [[ $ri_version == "ri 1.8a" ]]; then
classes=( $( ruby -W0 $ri_path | \
ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
@@ -75,9 +104,11 @@ _ri()
fi
COMPREPLY=( $( compgen -W '${classes[@]}' -- "$cur" ) )
+ __ltrim_colon_completions "$cur"
+
if [[ "$cur" == [A-Z]* ]]; then
# we're completing on class or module alone
- return 0
+ return
fi
# we're completing on methods
@@ -86,4 +117,4 @@ _ri()
} &&
complete -F _ri ri
-# ex: ts=4 sw=4 et filetype=sh
+# ex: filetype=sh