@@ -422,26 +422,27 @@ _comp_compgen__error_fallback()
422422# The array name should not start with an underscores "_", which is
423423# internally used. The array name should not be either "IFS" or
424424# "OPT{IND,ARG,ERR}".
425- # -F sep Set a set of separator characters (used as IFS in evaluating
426- # `compgen'). The default separator is $' \t\n'. Note that this is
427- # not the set of separators to delimit output of `compgen', but the
428- # separators in evaluating the expansions of `-W '...'`, etc. The
429- # delimiter of the output of `compgen` is always a newline.
430- # -l The same as -F $'\n'. Use lines as words in evaluating compgen.
431425# -c cur Set a word used as a prefix to filter the completions. The default
432426# is ${cur-}.
433427# -R The same as -c ''. Use raw outputs without filtering.
434428# -C dir Evaluate compgen/generator in the specified directory.
435429# @var[in,opt] cur Used as the default value of a prefix to filter the
436430# completions.
437431#
438- # Usage #1: _comp_compgen [-alR|-F sep|-v arr|-c cur] -- options...
432+ # Usage #1: _comp_compgen [-alR|-F sep|-v arr|-c cur|-C dir ] -- options...
439433# Call `compgen` with the specified arguments and store the results in the
440434# specified array. This function essentially performs arr=($(compgen args...))
441435# but properly handles shell options, IFS, etc. using _comp_split. This
442436# function is equivalent to `_comp_split [-a] -l arr "$(IFS=sep; compgen
443437# args... -- cur)"`, but this pattern is frequent in the codebase and is good
444438# to separate out as a function for the possible future implementation change.
439+ # OPTIONS
440+ # -F sep Set a set of separator characters (used as IFS in evaluating
441+ # `compgen'). The default separator is $' \t\n'. Note that this is
442+ # not the set of separators to delimit output of `compgen', but the
443+ # separators in evaluating the expansions of `-W '...'`, etc. The
444+ # delimiter of the output of `compgen` is always a newline.
445+ # -l The same as -F $'\n'. Use lines as words in evaluating compgen.
445446# @param $1... options Arguments that are passed to compgen (if $1 starts with
446447# a hyphen `-`).
447448#
@@ -456,7 +457,7 @@ _comp_compgen__error_fallback()
456457# @return True (0) if at least one completion is generated, False (1) if no
457458# completion is generated, or 2 with an incorrect usage.
458459#
459- # Usage #2: _comp_compgen [-alR |-v arr|-c cur] name args...
460+ # Usage #2: _comp_compgen [-aR |-v arr|-c cur|-C dir ] name args...
460461# Call the generator `_comp_compgen_NAME ARGS...` with the specified options.
461462# This provides a common interface to call the functions `_comp_compgen_NAME`,
462463# which produce completion candidates, with custom options [-alR|-v arr|-c
@@ -505,15 +506,17 @@ _comp_compgen()
505506 local _append=${_comp_compgen__append-}
506507 local _var=${_comp_compgen__var-COMPREPLY}
507508 local _cur=${_comp_compgen__cur-${cur-} }
508- local _ifs=$' \t\n ' _dir=" "
509+ local _dir=" "
510+ local _ifs=$' \t\n ' _has_ifs=" "
511+ local _icmd=" " _xcmd=" "
509512
510513 local _old_nocasematch=" "
511514 if shopt -q nocasematch; then
512515 _old_nocasematch=set
513516 shopt -u nocasematch
514517 fi
515518 local OPTIND=1 OPTARG=" " OPTERR=0 _opt
516- while getopts ' :alF:v: Rc:C:' _opt " $@ " ; do
519+ while getopts ' :av: Rc:C:lF :' _opt " $@ " ; do
517520 case $_opt in
518521 a) _append=set ;;
519522 v)
@@ -523,8 +526,6 @@ _comp_compgen()
523526 fi
524527 _var=$OPTARG
525528 ;;
526- l) _ifs=$' \n ' ;;
527- F) _ifs=$OPTARG ;;
528529 c) _cur=$OPTARG ;;
529530 R) _cur=" " ;;
530531 C)
@@ -534,6 +535,8 @@ _comp_compgen()
534535 fi
535536 _dir=$OPTARG
536537 ;;
538+ l) _has_ifs=set _ifs=$' \n ' ;;
539+ F) _has_ifs=set _ifs=$OPTARG ;;
537540 * )
538541 printf ' bash_completion: %s: usage error\n' " $FUNCNAME " >&2
539542 return 2
@@ -550,6 +553,11 @@ _comp_compgen()
550553
551554 if [[ $1 != -* ]]; then
552555 # usage: _comp_compgen [options] NAME args
556+ if [[ $_has_ifs ]]; then
557+ printf ' bash_completion: %s: `-l' \' ' and `-F sep' \' ' are not supported for generators\n' " $FUNCNAME " >&2
558+ return 2
559+ fi
560+
553561 if ! declare -F " _comp_compgen_$1 " & > /dev/null; then
554562 printf ' bash_completion: %s: unrecognized category `%s' \' ' (function _comp_compgen_%s not found)\n' " $FUNCNAME " " $1 " " $1 " >&2
555563 return 2
0 commit comments