@@ -2156,16 +2156,16 @@ _comp_realcommand()
2156
2156
fi
2157
2157
}
2158
2158
2159
- # This function returns the first argument, excluding options
2159
+ # This function returns the position of the first argument, excluding options
2160
2160
#
2161
2161
# Options:
2162
2162
# -a GLOB Pattern of options that take an option argument
2163
2163
#
2164
- # @var[out] ret First argument before current being completed if any, or
2165
- # otherwise an empty string
2164
+ # @var[out] ret Position of the first argument before the current one being
2165
+ # completed if any, or otherwise an empty string
2166
2166
# @return True (0) if any argument is found, False (> 0) otherwise.
2167
2167
# @since 2.12
2168
- _comp_get_first_arg ()
2168
+ _comp_locate_first_arg ()
2169
2169
{
2170
2170
local has_optarg=" "
2171
2171
local OPTIND=1 OPTARG=" " OPTERR=0 _opt
@@ -2187,16 +2187,30 @@ _comp_get_first_arg()
2187
2187
if [[ $has_optarg && ${words[i]} == $has_optarg ]]; then
2188
2188
(( i++ ))
2189
2189
elif [[ ${words[i]} != -?* ]]; then
2190
- ret=${words[i]}
2190
+ ret=$i
2191
2191
return 0
2192
2192
elif [[ ${words[i]} == -- ]]; then
2193
- (( i + 1 < cword)) && ret=${words[ i + 1]} && return 0
2193
+ (( i + 1 < cword)) && ret=$(( i + 1 )) && return 0
2194
2194
break
2195
2195
fi
2196
2196
done
2197
2197
return 1
2198
2198
}
2199
2199
2200
+ # This function returns the first argument, excluding options
2201
+ #
2202
+ # Options:
2203
+ # -a GLOB Pattern of options that take an option argument
2204
+ #
2205
+ # @var[out] ret First argument before the current one being completed if any,
2206
+ # or otherwise an empty string
2207
+ # @return True (0) if any argument is found, False (> 0) otherwise.
2208
+ # @since 2.12
2209
+ _comp_get_first_arg ()
2210
+ {
2211
+ _comp_locate_first_arg " $@ " && ret=${words[ret]}
2212
+ }
2213
+
2200
2214
# This function counts the number of args, excluding options
2201
2215
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
2202
2216
# NOT be considered word breaks. See _comp__reassemble_words.
0 commit comments