@@ -257,17 +257,19 @@ _upvars()
257
257
#
258
258
# Options:
259
259
# -E $2 is interpreted as a POSIX extended regular expression.
260
- # This is always the partial matching unless ^, $ is included
261
- # in $2.
262
- # -F $2 is interpreted as a fixed string.
263
- # -G $2 is interpreted as a glob pattern.
264
- #
265
- # -p Combined with -F or -G, it performs the prefix matching.
266
- # -s Combined with -F or -G, it performs the suffix matching.
267
- # -m Combined with -F or -G, it performs the middle matching.
260
+ # The default anchoring is `-m` (see below).
261
+ # -F $2 is interpreted as a fixed string. The default anchoring
262
+ # is `-m` (see below).
263
+ # -G $2 is interpreted as a glob pattern. The default anchoring
264
+ # is `-x` (see below).
265
+ #
266
+ # -p Combined with -EFG, it performs the prefix matching.
267
+ # -s Combined with -EFG, it performs the suffix matching.
268
+ # -m Combined with -EFG, it performs the middle matching.
269
+ # -x Combined with -EFG, it performs the exact matching.
270
+ #
268
271
# -r Revert the condition, i.e., remove elements that satisfy
269
272
# the original condition.
270
- #
271
273
# -C Array compaction is not performed.
272
274
#
273
275
# @return 2 with a wrong usage, 1 when any elements are removed, 0 when the set
@@ -278,14 +280,14 @@ _comp_array_filter()
278
280
{
279
281
local _comp_local_flags=' ' _comp_local_pattype=' ' _comp_local_anchoring=' '
280
282
local OPTIND=1 OPTARG=' ' OPTERR=0 _comp_local_opt=' '
281
- while getopts ' EFGpsmrC ' _comp_local_opt " $@ " ; do
283
+ while getopts ' EFGpsmxrC ' _comp_local_opt " $@ " ; do
282
284
case $_comp_local_opt in
283
285
[EFG]) _comp_local_pattype=$_comp_local_opt ;;
284
- [psm ]) _comp_local_anchoring=$_comp_local_opt ;;
286
+ [psmx ]) _comp_local_anchoring=$_comp_local_opt ;;
285
287
[rC]) _comp_local_flags=$_comp_local_opt$_comp_local_flags ;;
286
288
* )
287
289
printf ' bash_completion: %s: %s\n' " $FUNCNAME " ' usage error' >&2
288
- printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmrC ] ARRAY_NAME CONDITION" >&2
290
+ printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmxrC ] ARRAY_NAME CONDITION" >&2
289
291
return 2
290
292
;;
291
293
esac
@@ -294,7 +296,7 @@ _comp_array_filter()
294
296
shift $(( OPTIND - 1 ))
295
297
if (( $# != 2 )) ; then
296
298
printf ' bash_completion: %s: %s\n' " $FUNCNAME " " unexpected number of arguments: $# " >&2
297
- printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmrC ] ARRAY_NAME CONDITION" >&2
299
+ printf ' usage: %s %s\n' " $FUNCNAME " " [-EFGpsmxrC ] ARRAY_NAME CONDITION" >&2
298
300
return 2
299
301
elif [[ $1 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
300
302
printf ' bash_completion: %s: %s\n' " $FUNCNAME " " invalid array name '$1 '." >&2
@@ -312,14 +314,19 @@ _comp_array_filter()
312
314
local _comp_local_predicate=' ' _comp_local_pattern=$2
313
315
case $_comp_local_pattype in
314
316
E)
315
- _comp_local_predicate=' [[ $_comp_local_value =~ $_comp_local_pattern ]]'
317
+ case $_comp_local_anchoring in
318
+ p) _comp_local_predicate=' [[ $_comp_local_value =~ ^($_comp_local_pattern) ]]' ;;
319
+ s) _comp_local_predicate=' [[ $_comp_local_value =~ ($_comp_local_pattern)$ ]]' ;;
320
+ x) _comp_local_predicate=' [[ $_comp_local_value =~ ^($_comp_local_pattern)$ ]]' ;;
321
+ * ) _comp_local_predicate=' [[ $_comp_local_value =~ $_comp_local_pattern ]]' ;;
322
+ esac
316
323
;;
317
324
F)
318
325
case $_comp_local_anchoring in
319
326
p) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern"* ]]' ;;
320
327
s) _comp_local_predicate=' [[ $_comp_local_value == *"$_comp_local_pattern" ]]' ;;
321
- m ) _comp_local_predicate=' [[ $_comp_local_value == * "$_comp_local_pattern"* ]]' ;;
322
- * ) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern" ]]' ;;
328
+ x ) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern" ]]' ;;
329
+ * ) _comp_local_predicate=' [[ $_comp_local_value == * "$_comp_local_pattern"* ]]' ;;
323
330
esac
324
331
;;
325
332
G)
0 commit comments