@@ -257,17 +257,19 @@ _upvars()
257257#
258258# Options:
259259# -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+ #
268271# -r Revert the condition, i.e., remove elements that satisfy
269272# the original condition.
270- #
271273# -C Array compaction is not performed.
272274#
273275# @return 2 with a wrong usage, 1 when any elements are removed, 0 when the set
@@ -278,14 +280,14 @@ _comp_array_filter()
278280{
279281 local _comp_local_flags=' ' _comp_local_pattype=' ' _comp_local_anchoring=' '
280282 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
282284 case $_comp_local_opt in
283285 [EFG]) _comp_local_pattype=$_comp_local_opt ;;
284- [psm ]) _comp_local_anchoring=$_comp_local_opt ;;
286+ [psmx ]) _comp_local_anchoring=$_comp_local_opt ;;
285287 [rC]) _comp_local_flags=$_comp_local_opt$_comp_local_flags ;;
286288 * )
287289 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
289291 return 2
290292 ;;
291293 esac
@@ -294,7 +296,7 @@ _comp_array_filter()
294296 shift $(( OPTIND - 1 ))
295297 if (( $# != 2 )) ; then
296298 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
298300 return 2
299301 elif [[ $1 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
300302 printf ' bash_completion: %s: %s\n' " $FUNCNAME " " invalid array name '$1 '." >&2
@@ -312,14 +314,19 @@ _comp_array_filter()
312314 local _comp_local_predicate=' ' _comp_local_pattern=$2
313315 case $_comp_local_pattype in
314316 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
316323 ;;
317324 F)
318325 case $_comp_local_anchoring in
319326 p) _comp_local_predicate=' [[ $_comp_local_value == "$_comp_local_pattern"* ]]' ;;
320327 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"* ]]' ;;
323330 esac
324331 ;;
325332 G)
0 commit comments