Skip to content

Commit 7a16ad4

Browse files
committed
fix(_comp_{last_index,index_of})!: return result through ret
1 parent e9e6788 commit 7a16ad4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

completions/ARRAY

+12-5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ _comp_xfunc_ARRAY_filter()
151151
[[ ! $_unset ]]
152152
}
153153

154+
# @version bash-4.3
154155
_comp_uniq()
155156
{
156157
local -n _comp_uniq__array=$1
@@ -163,36 +164,42 @@ _comp_uniq()
163164
done
164165
}
165166

167+
# Obtain the largest index
168+
# @var[out] ret
169+
# @version bash-4.3
166170
_comp_last_index()
167171
{
168-
local -n _comp_last_index__array=$1 _comp_last_index__ret=$2
172+
local -n _comp_last_index__array=$1
169173
local -a _comp_last_index__indices=("${!_comp_last_index__array[@]}")
170-
_comp_last_index__ret=${_comp_last_index__indices[*]: -1}
174+
ret=${_comp_last_index__indices[*]: -1}
171175
}
172176

177+
# @version bash-4.3
173178
_comp_compact()
174179
{
175180
local -n _comp_compact__array=$1
176181
_comp_compact__array=("${_comp_compact__array[@]}")
177182
}
178183

184+
# Find the index of a matching element
185+
# @var[out] ret
186+
# @version bash-4.3
179187
_comp_index_of()
180188
{
181189
# TODO getopts -> -r gets rightmost (last) index
182190
# TODO getopts: -R uses regex instead of glob
183191
local -n _comp_index_of__array=$1
184192
local _comp_compact__pattern=$2
185-
local -n _comp_index_of__ret=$3
186193

187194
local -i _comp_index_of__i
188195
for _comp_index_of__i in "${!_comp_index_of__array[@]}"; do
189196
# shellcheck disable=SC2053
190197
if [[ ${_comp_index_of__array[_comp_index_of__i]} == $_comp_compact__pattern ]]; then
191-
_comp_index_of__ret=$_comp_index_of__i
198+
ret=$_comp_index_of__i
192199
return 0
193200
fi
194201
done
195202

196-
_comp_index_of__ret=-1
203+
ret=-1
197204
return 1
198205
}

0 commit comments

Comments
 (0)