@@ -422,26 +422,27 @@ _comp_compgen__error_fallback()
422
422
# The array name should not start with an underscores "_", which is
423
423
# internally used. The array name should not be either "IFS" or
424
424
# "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.
431
425
# -c cur Set a word used as a prefix to filter the completions. The default
432
426
# is ${cur-}.
433
427
# -R The same as -c ''. Use raw outputs without filtering.
434
428
# -C dir Evaluate compgen/generator in the specified directory.
435
429
# @var[in,opt] cur Used as the default value of a prefix to filter the
436
430
# completions.
437
431
#
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...
439
433
# Call `compgen` with the specified arguments and store the results in the
440
434
# specified array. This function essentially performs arr=($(compgen args...))
441
435
# but properly handles shell options, IFS, etc. using _comp_split. This
442
436
# function is equivalent to `_comp_split [-a] -l arr "$(IFS=sep; compgen
443
437
# args... -- cur)"`, but this pattern is frequent in the codebase and is good
444
438
# 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.
445
446
# @param $1... options Arguments that are passed to compgen (if $1 starts with
446
447
# a hyphen `-`).
447
448
#
@@ -456,7 +457,7 @@ _comp_compgen__error_fallback()
456
457
# @return True (0) if at least one completion is generated, False (1) if no
457
458
# completion is generated, or 2 with an incorrect usage.
458
459
#
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...
460
461
# Call the generator `_comp_compgen_NAME ARGS...` with the specified options.
461
462
# This provides a common interface to call the functions `_comp_compgen_NAME`,
462
463
# which produce completion candidates, with custom options [-alR|-v arr|-c
@@ -505,15 +506,17 @@ _comp_compgen()
505
506
local _append=${_comp_compgen__append-}
506
507
local _var=${_comp_compgen__var-COMPREPLY}
507
508
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=" "
509
512
510
513
local _old_nocasematch=" "
511
514
if shopt -q nocasematch; then
512
515
_old_nocasematch=set
513
516
shopt -u nocasematch
514
517
fi
515
518
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
517
520
case $_opt in
518
521
a) _append=set ;;
519
522
v)
@@ -523,8 +526,6 @@ _comp_compgen()
523
526
fi
524
527
_var=$OPTARG
525
528
;;
526
- l) _ifs=$' \n ' ;;
527
- F) _ifs=$OPTARG ;;
528
529
c) _cur=$OPTARG ;;
529
530
R) _cur=" " ;;
530
531
C)
@@ -534,6 +535,8 @@ _comp_compgen()
534
535
fi
535
536
_dir=$OPTARG
536
537
;;
538
+ l) _has_ifs=set _ifs=$' \n ' ;;
539
+ F) _has_ifs=set _ifs=$OPTARG ;;
537
540
* )
538
541
printf ' bash_completion: %s: usage error\n' " $FUNCNAME " >&2
539
542
return 2
@@ -550,6 +553,11 @@ _comp_compgen()
550
553
551
554
if [[ $1 != -* ]]; then
552
555
# 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
+
553
561
if ! declare -F " _comp_compgen_$1 " & > /dev/null; then
554
562
printf ' bash_completion: %s: unrecognized category `%s' \' ' (function _comp_compgen_%s not found)\n' " $FUNCNAME " " $1 " " $1 " >&2
555
563
return 2
0 commit comments