Skip to content

Commit febe8fd

Browse files
committed
fix(ri): split classes using _comp_split
1 parent 58ac884 commit febe8fd

File tree

1 file changed

+11
-13
lines changed
  • completions

1 file changed

+11
-13
lines changed

completions/ri

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _comp_cmd_ri()
7070
return
7171
fi
7272

73-
local class method prefix="" ri_path ri_version ri_major="" separator IFS
73+
local class method prefix="" ri_path ri_version ri_major="" separator
7474
local -a classes
7575

7676
ri_path=$(type -p ri)
@@ -82,35 +82,33 @@ _comp_cmd_ri()
8282
[[ $ri_version =~ ri[[:space:]]v?([0-9]+) ]] && ri_major=${BASH_REMATCH[1]}
8383

8484
# need to also split on commas
85-
IFS=$', \n\t'
8685
if [[ $cur == [A-Z]*[#.]* ]]; then
8786
[[ $cur == *#* ]] && separator=# || separator=.
8887
# we're completing on class and method
8988
class=${cur%"$separator"*}
9089
method=${cur#*"$separator"}
91-
classes=($class)
90+
_comp_split -F $', \n\t' classes "$class"
9291
prefix=$class$separator
9392
_comp_compgen -c "$method" -i ri methods
9493
return
9594
fi
9695

9796
if [[ $ri_version == integrated ]]; then
9897
# integrated ri from Ruby 1.9
99-
classes=($(ri -c 2>/dev/null | ruby -ne 'if /^\s*$/..$stdin.eof then \
100-
if /^ +[A-Z]/ then print; end; end' 2>/dev/null))
98+
_comp_split -F $', \n\t' classes \
99+
"$(ri -c 2>/dev/null | ruby -ne 'if /^\s*$/..$stdin.eof then \
100+
if /^ +[A-Z]/ then print; end; end' 2>/dev/null)"
101101
elif [[ $ri_major && $ri_major -ge 3 ]]; then
102-
classes=($(ri -l 2>/dev/null))
102+
_comp_split -F $', \n\t' classes "$(ri -l 2>/dev/null)"
103103
elif [[ $ri_version == "ri 1.8a" ]]; then
104-
classes=($(ruby -W0 "$ri_path" |
104+
_comp_split -F $', \n\t' classes "$(ruby -W0 "$ri_path" |
105105
ruby -ne 'if /^'"'"'ri'"'"' has/..$stdin.eof then \
106-
if /^ .*[A-Z]/ then print; end; end'))
106+
if /^ .*[A-Z]/ then print; end; end')"
107107
else
108-
classes=($(ruby -W0 "$ri_path" |
108+
_comp_split -F $', \n\t' classes "$(ruby -W0 "$ri_path" |
109109
ruby -ne 'if /^I have/..$stdin.eof then \
110-
if /^ .*[A-Z]/ then print; end; end'))
111-
fi
112-
113-
((${#classes[@]})) &&
110+
if /^ .*[A-Z]/ then print; end; end')"
111+
fi &&
114112
_comp_compgen -- -W '"${classes[@]}"'
115113
_comp_ltrim_colon_completions "$cur"
116114

0 commit comments

Comments
 (0)