4141shopt -s extglob progcomp
4242
4343# Declare a compatibility function name
44- # @param $1 Old function name
45- # @param $2 New function name
44+ # @param $1 Version of bash-completion where the deprecation occurred
45+ # @param $2 Old function name
46+ # @param $3 New function name
47+ # @since 2.12
4648_comp_deprecate_func ()
4749{
48- if [[ $1 != [a-zA-Z_] * ([a-zA-Z_0-9]) ]] ; then
49- printf ' bash_completion: %s: %s \n' " $FUNCNAME " " \$ 1: invalid function name ' $1 ' " >&2
50+ if (( $# != 3 )) ; then
51+ printf ' bash_completion: %s: usage: %s OLD_NAME NEW_NAME DEPRECATION_VERSION \n' " $FUNCNAME " " $FUNCNAME "
5052 return 2
51- elif [[ $2 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
52- printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 2: invalid function name '$2 '" >&2
53+ fi
54+ if [[ $2 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
55+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 2: invalid function name '$1 '" >&2
56+ return 2
57+ elif [[ $3 != [a-zA-Z_]* ([a-zA-Z_0-9]) ]]; then
58+ printf ' bash_completion: %s: %s\n' " $FUNCNAME " " \$ 3: invalid function name '$2 '" >&2
5359 return 2
5460 fi
55- eval -- " $1 () { $2 \"\$ @\" ; }"
61+ eval -- " $2 () { $3 \"\$ @\" ; }"
5662}
5763
5864# A lot of the following one-liners were taken directly from the
@@ -91,6 +97,7 @@ complete -b builtin
9197
9298# Check if we're running on the given userland
9399# @param $1 userland to check for
100+ # @since 2.12
94101_comp_userland ()
95102{
96103 local userland=$( uname -s)
@@ -100,6 +107,7 @@ _comp_userland()
100107
101108# This function sets correct SysV init directories
102109#
110+ # @since 2.12
103111_comp_sysvdirs ()
104112{
105113 sysvdirs=()
@@ -112,6 +120,7 @@ _comp_sysvdirs()
112120
113121# This function checks whether we have a given program on the system.
114122#
123+ # @since 2.12
115124_comp_have_command ()
116125{
117126 # Completions for system administrator commands are installed as well in
@@ -122,6 +131,7 @@ _comp_have_command()
122131# This function checks whether a given readline variable
123132# is `on'.
124133#
134+ # @since 2.12
125135_comp_readline_variable_on ()
126136{
127137 [[ $( bind -v) == * $1 + ([[:space:]])on* ]]
@@ -130,6 +140,7 @@ _comp_readline_variable_on()
130140# This function shell-quotes the argument
131141# @param $1 String to be quoted
132142# @var[out] ret Resulting string
143+ # @since 2.12
133144_comp_quote ()
134145{
135146 ret=\' ${1// \' / \'\\\'\' } \'
@@ -189,6 +200,7 @@ _comp_dequote__initialize
189200# We allow these parameter expansions as a part of safe strings assuming the
190201# referential transparency of the simple parameter expansions and the sane
191202# setup of the variables by the user or other frameworks that the user loads.
203+ # @since 2.12
192204_comp_dequote ()
193205{
194206 ret=() # fallback value for unsafe word and failglob
@@ -202,6 +214,7 @@ _comp_dequote()
202214# variable in an unset state.
203215# Usage: local IFS='|'; _comp_unlocal IFS
204216# @param $* Variable names to be unset
217+ # @since 2.12
205218_comp_unlocal ()
206219{
207220 if (( BASH_VERSINFO[0 ] >= 5 )) && shopt -q localvar_unset; then
@@ -221,6 +234,7 @@ _comp_unlocal()
221234# -v Assign single value to varname
222235# @return 1 if error occurs
223236# @see https://fvue.nl/wiki/Bash:_Passing_variables_by_reference
237+ # @since 2.12
224238_comp_upvars ()
225239{
226240 if ! (( $# )) ; then
@@ -281,6 +295,7 @@ _comp_upvars()
281295# parameter expansions, command substitutions, and other expansions will be
282296# processed. The user-provided strings should not be directly specified to
283297# this argument.
298+ # @since 2.12
284299_comp_expand_glob ()
285300{
286301 if (( $# != 2 )) ; then
@@ -337,6 +352,7 @@ _comp_expand_glob()
337352# @return 2 when the usage is wrong, 0 when one or more completions are
338353# generated, or 1 when the execution succeeds but no candidates are
339354# generated.
355+ # @since 2.12
340356_comp_split ()
341357{
342358 local _append=" " IFS=$' \t\n '
@@ -462,6 +478,7 @@ _comp_split()
462478# supposed to replace the existing content of the array by default to allow the
463479# caller control whether to replace or append by the option `-a`.
464480#
481+ # @since 2.12
465482_comp_compgen ()
466483{
467484 local _append=${_comp_compgen__append-}
@@ -557,6 +574,7 @@ _comp_compgen()
557574# caller _comp_compgen, the words are appended to the existing elements of the
558575# array instead of replacing the existing elements. This function ignores
559576# ${cur-} or the prefix specified by `-v CUR`.
577+ # @since 2.12
560578_comp_compgen_set ()
561579{
562580 local _append=${_comp_compgen__append-}
@@ -567,6 +585,7 @@ _comp_compgen_set()
567585# Check if the argument looks like a path.
568586# @param $1 thing to check
569587# @return True (0) if it does, False (> 0) otherwise
588+ # @since 2.12
570589_comp_looks_like_path ()
571590{
572591 [[ ${1-} == @ (* /| [.~])* ]]
@@ -717,6 +736,7 @@ _comp__get_cword_at_cursor()
717736#
718737# $ _comp_get_words -n : cur prev
719738#
739+ # @since 2.12
720740_comp_get_words ()
721741{
722742 local exclude=" " flag i OPTIND=1
@@ -796,6 +816,7 @@ _comp_get_words()
796816# @param $1 current word to complete (cur)
797817# @modifies global array $COMPREPLY
798818#
819+ # @since 2.12
799820_comp_ltrim_colon_completions ()
800821{
801822 local i=${# COMPREPLY[*]}
@@ -825,6 +846,7 @@ _comp_ltrim_colon_completions()
825846# - https://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01944.html
826847# @param $1 Argument to quote
827848# @var[out] ret Quoted result is stored in this variable
849+ # @since 2.12
828850# shellcheck disable=SC2178 # The assignment is not intended for the global "ret"
829851_comp_quote_compgen ()
830852{
@@ -852,6 +874,7 @@ _comp_quote_compgen()
852874# completions with `.$1' and the uppercase version of it as file
853875# extension.
854876#
877+ # @since 2.12
855878_comp_compgen_filedir ()
856879{
857880 _comp_compgen_tilde && return
@@ -972,6 +995,7 @@ _variables()
972995#
973996# Usage: [-k] DELIMITER COMPGEN_ARG...
974997# -k: do not filter out already present tokens in value
998+ # @since 2.12
975999_comp_delimited ()
9761000{
9771001 local prefix=" " delimiter=$1 deduplicate=set
@@ -1035,6 +1059,7 @@ _comp_delimited()
10351059# @param $1 variable assignment to be completed
10361060# @return True (0) if variable value completion was attempted,
10371061# False (> 0) if not.
1062+ # @since 2.12
10381063_comp_variable_assignments ()
10391064{
10401065 local cur=${1-} i
@@ -1113,6 +1138,7 @@ _comp_variable_assignments()
11131138# @return True (0) if completion needs further processing,
11141139# False (> 0) no further processing is necessary.
11151140#
1141+ # @since 2.12
11161142_comp_initialize ()
11171143{
11181144 local exclude=" " opt_split=" " outx errx inx
@@ -1280,6 +1306,7 @@ _comp_compgen_help__parse()
12801306# When no arguments are specified, `--help` is assumed.
12811307#
12821308# @var[in] comp_args[0 ]
1309+ # @since 2 .12
12831310_comp_compgen_help()
12841311{
12851312 (($# )) || set -- -- --help
@@ -1311,6 +1338,7 @@ _comp_compgen_help()
13111338# When no arguments are specified, `--usage` is assumed.
13121339#
13131340# @var[in] comp_args[0]
1341+ # @since 2.12
13141342_comp_compgen_usage ()
13151343{
13161344 (( $# )) || set -- -- --usage
@@ -1493,6 +1521,7 @@ _ncpus()
14931521# @return False (1) if completion needs further processing,
14941522# True (0) if tilde is followed by a valid username, completions are
14951523# put in COMPREPLY and no further processing is necessary.
1524+ # @since 2.12
14961525_comp_compgen_tilde ()
14971526{
14981527 if [[ ${cur-} == \~ * && $cur != * /* ]]; then
@@ -1848,6 +1877,7 @@ _allowed_groups()
18481877 fi
18491878}
18501879
1880+ # @since 2.12
18511881_comp_selinux_users ()
18521882{
18531883 _comp_compgen -a -- -W ' $(
@@ -1896,6 +1926,7 @@ _fstypes()
18961926# see `_comp_realcommand` for those.
18971927# @param $1 The file
18981928# @var[out] ret The path
1929+ # @since 2.12
18991930_comp_abspath ()
19001931{
19011932 ret=$1
@@ -1916,6 +1947,7 @@ _comp_abspath()
19161947# @param $1 Command
19171948# @var[out] ret Resulting string
19181949# @return True (0) if command found, False (> 0) if not.
1950+ # @since 2.12
19191951_comp_realcommand ()
19201952{
19211953 ret=" "
@@ -2367,6 +2399,7 @@ _comp__find_original_word()
23672399# first complete on a command, then complete according to that command's own
23682400# completion definition.
23692401#
2402+ # @since 2.12
23702403_comp_command_offset ()
23712404{
23722405 # rewrite current completion context before invoking
@@ -2484,6 +2517,7 @@ _comp_command_offset()
24842517# Only intended to be used as a completion function directly associated
24852518# with a command, not to be invoked from within other completion functions.
24862519#
2520+ # @since 2.12
24872521_comp_command ()
24882522{
24892523 # We unset the shell variable `words` locally to tell
@@ -2507,6 +2541,7 @@ _comp_command()
25072541complete -F _comp_command aoss command " do" else eval exec ltrace nice nohup padsp \
25082542 " then" time tsocks vsound xargs
25092543
2544+ # @since 2.12
25102545_comp_root_command ()
25112546{
25122547 local PATH=$PATH :/sbin:/usr/sbin:/usr/local/sbin
@@ -2522,6 +2557,7 @@ _complete_as_root()
25222557 [[ $EUID -eq 0 || ${root_command-} ]]
25232558}
25242559
2560+ # @since 2.12
25252561_comp_longopt ()
25262562{
25272563 local cur prev words cword was_split comp_args
@@ -2841,6 +2877,7 @@ _completion_loader()
28412877# `_comp_xfunc_${1//[^a-zA-Z0-9_]/_}_$2' is used for the actual name of the
28422878# shell function.
28432879# @param $3... if any, specifies the arguments that are passed to the xfunc.
2880+ # @since 2.12
28442881_comp_xfunc ()
28452882{
28462883 local xfunc_name=$2
0 commit comments