Skip to content

Commit 7d7b961

Browse files
committed
fix(xfunc ARRAY filter): support exit status 27 or predicate
1 parent 72ddb92 commit 7d7b961

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

completions/ARRAY

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
# Filter the array elements with the specified condition.
44
# @param $1 Array name (that is not "value" or other internal variable names)
5-
# @param $2 When none of the options -EFG are specified, this is used as the
6-
# command that tests the array element. The command is supposed to exit with
7-
# status 0 when the element should be preserved, and 1 when the element
8-
# should be removed. The other exit status will cancel the array filtering.
9-
# If this is an existing function name, the function is called with the value
10-
# of the array element. Otherwise, this shall be the shell command that
11-
# tests the array-element value stored in the shell variable "value".
5+
# @param $2 When any of the options `-EFG' is specified, the second argument is
6+
# used as a pattern string whose meaning is determined by the option `-EFG'.
7+
# Otherwise, the second argument specifies the command that tests the array
8+
# element. The command is supposed to exit with:
9+
#
10+
# status 0 .... when the element should be preserved
11+
# status 1 .... when the element should be removed
12+
# status 27 ... when the loop should be canceled. All the remaining
13+
# elements will be preserved regardless of the presence of
14+
# option `-r'.
15+
#
16+
# The other exit status will cancel the array filtering. If this is an
17+
# existing command name, the function is called with the value of the array
18+
# element. Otherwise, this shall be the shell command that tests the
19+
# array-element value stored in the shell variable "value".
1220
#
1321
# Options:
1422
# -E $2 is interpreted as a POSIX extended regular expression.
@@ -114,6 +122,7 @@ _comp_xfunc_ARRAY_filter()
114122
unset -v "$1[\$_comp_local_index]"
115123
_comp_local_unset=1
116124
;;
125+
27) break ;;
117126
*)
118127
printf 'bash_completion: %s: %s\n' "$FUNCNAME" \
119128
"the filter condition broken '${_comp_local_pattype:+-$_comp_local_pattype }$2'" >&2

0 commit comments

Comments
 (0)