41
41
shopt -s extglob progcomp
42
42
43
43
# 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
46
48
_comp_deprecate_func ()
47
49
{
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 "
50
52
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
53
59
return 2
54
60
fi
55
- eval -- " $1 () { $2 \"\$ @\" ; }"
61
+ eval -- " $2 () { $3 \"\$ @\" ; }"
56
62
}
57
63
58
64
# A lot of the following one-liners were taken directly from the
@@ -91,6 +97,7 @@ complete -b builtin
91
97
92
98
# Check if we're running on the given userland
93
99
# @param $1 userland to check for
100
+ # @since 2.12
94
101
_comp_userland ()
95
102
{
96
103
local userland=$( uname -s)
@@ -100,6 +107,7 @@ _comp_userland()
100
107
101
108
# This function sets correct SysV init directories
102
109
#
110
+ # @since 2.12
103
111
_comp_sysvdirs ()
104
112
{
105
113
sysvdirs=()
@@ -112,6 +120,7 @@ _comp_sysvdirs()
112
120
113
121
# This function checks whether we have a given program on the system.
114
122
#
123
+ # @since 2.12
115
124
_comp_have_command ()
116
125
{
117
126
# Completions for system administrator commands are installed as well in
@@ -122,6 +131,7 @@ _comp_have_command()
122
131
# This function checks whether a given readline variable
123
132
# is `on'.
124
133
#
134
+ # @since 2.12
125
135
_comp_readline_variable_on ()
126
136
{
127
137
[[ $( bind -v) == * $1 + ([[:space:]])on* ]]
@@ -130,6 +140,7 @@ _comp_readline_variable_on()
130
140
# This function shell-quotes the argument
131
141
# @param $1 String to be quoted
132
142
# @var[out] ret Resulting string
143
+ # @since 2.12
133
144
_comp_quote ()
134
145
{
135
146
ret=\' ${1// \' / \'\\\'\' } \'
@@ -189,6 +200,7 @@ _comp_dequote__initialize
189
200
# We allow these parameter expansions as a part of safe strings assuming the
190
201
# referential transparency of the simple parameter expansions and the sane
191
202
# setup of the variables by the user or other frameworks that the user loads.
203
+ # @since 2.12
192
204
_comp_dequote ()
193
205
{
194
206
ret=() # fallback value for unsafe word and failglob
@@ -202,6 +214,7 @@ _comp_dequote()
202
214
# variable in an unset state.
203
215
# Usage: local IFS='|'; _comp_unlocal IFS
204
216
# @param $* Variable names to be unset
217
+ # @since 2.12
205
218
_comp_unlocal ()
206
219
{
207
220
if (( BASH_VERSINFO[0 ] >= 5 )) && shopt -q localvar_unset; then
@@ -221,6 +234,7 @@ _comp_unlocal()
221
234
# -v Assign single value to varname
222
235
# @return 1 if error occurs
223
236
# @see https://fvue.nl/wiki/Bash:_Passing_variables_by_reference
237
+ # @since 2.12
224
238
_comp_upvars ()
225
239
{
226
240
if ! (( $# )) ; then
@@ -281,6 +295,7 @@ _comp_upvars()
281
295
# parameter expansions, command substitutions, and other expansions will be
282
296
# processed. The user-provided strings should not be directly specified to
283
297
# this argument.
298
+ # @since 2.12
284
299
_comp_expand_glob ()
285
300
{
286
301
if (( $# != 2 )) ; then
@@ -337,6 +352,7 @@ _comp_expand_glob()
337
352
# @return 2 when the usage is wrong, 0 when one or more completions are
338
353
# generated, or 1 when the execution succeeds but no candidates are
339
354
# generated.
355
+ # @since 2.12
340
356
_comp_split ()
341
357
{
342
358
local _append=" " IFS=$' \t\n '
@@ -462,6 +478,7 @@ _comp_split()
462
478
# supposed to replace the existing content of the array by default to allow the
463
479
# caller control whether to replace or append by the option `-a`.
464
480
#
481
+ # @since 2.12
465
482
_comp_compgen ()
466
483
{
467
484
local _append=${_comp_compgen__append-}
@@ -557,6 +574,7 @@ _comp_compgen()
557
574
# caller _comp_compgen, the words are appended to the existing elements of the
558
575
# array instead of replacing the existing elements. This function ignores
559
576
# ${cur-} or the prefix specified by `-v CUR`.
577
+ # @since 2.12
560
578
_comp_compgen_set ()
561
579
{
562
580
local _append=${_comp_compgen__append-}
@@ -567,6 +585,7 @@ _comp_compgen_set()
567
585
# Check if the argument looks like a path.
568
586
# @param $1 thing to check
569
587
# @return True (0) if it does, False (> 0) otherwise
588
+ # @since 2.12
570
589
_comp_looks_like_path ()
571
590
{
572
591
[[ ${1-} == @ (* /| [.~])* ]]
@@ -717,6 +736,7 @@ _comp__get_cword_at_cursor()
717
736
#
718
737
# $ _comp_get_words -n : cur prev
719
738
#
739
+ # @since 2.12
720
740
_comp_get_words ()
721
741
{
722
742
local exclude=" " flag i OPTIND=1
@@ -796,6 +816,7 @@ _comp_get_words()
796
816
# @param $1 current word to complete (cur)
797
817
# @modifies global array $COMPREPLY
798
818
#
819
+ # @since 2.12
799
820
_comp_ltrim_colon_completions ()
800
821
{
801
822
local i=${# COMPREPLY[*]}
@@ -825,6 +846,7 @@ _comp_ltrim_colon_completions()
825
846
# - https://www.mail-archive.com/bash-completion-devel@lists.alioth.debian.org/msg01944.html
826
847
# @param $1 Argument to quote
827
848
# @var[out] ret Quoted result is stored in this variable
849
+ # @since 2.12
828
850
# shellcheck disable=SC2178 # The assignment is not intended for the global "ret"
829
851
_comp_quote_compgen ()
830
852
{
@@ -852,6 +874,7 @@ _comp_quote_compgen()
852
874
# completions with `.$1' and the uppercase version of it as file
853
875
# extension.
854
876
#
877
+ # @since 2.12
855
878
_comp_compgen_filedir ()
856
879
{
857
880
_comp_compgen_tilde && return
@@ -972,6 +995,7 @@ _variables()
972
995
#
973
996
# Usage: [-k] DELIMITER COMPGEN_ARG...
974
997
# -k: do not filter out already present tokens in value
998
+ # @since 2.12
975
999
_comp_delimited ()
976
1000
{
977
1001
local prefix=" " delimiter=$1 deduplicate=set
@@ -1035,6 +1059,7 @@ _comp_delimited()
1035
1059
# @param $1 variable assignment to be completed
1036
1060
# @return True (0) if variable value completion was attempted,
1037
1061
# False (> 0) if not.
1062
+ # @since 2.12
1038
1063
_comp_variable_assignments ()
1039
1064
{
1040
1065
local cur=${1-} i
@@ -1113,6 +1138,7 @@ _comp_variable_assignments()
1113
1138
# @return True (0) if completion needs further processing,
1114
1139
# False (> 0) no further processing is necessary.
1115
1140
#
1141
+ # @since 2.12
1116
1142
_comp_initialize ()
1117
1143
{
1118
1144
local exclude=" " opt_split=" " outx errx inx
@@ -1280,6 +1306,7 @@ _comp_compgen_help__parse()
1280
1306
# When no arguments are specified, `--help` is assumed.
1281
1307
#
1282
1308
# @var[in] comp_args[0 ]
1309
+ # @since 2 .12
1283
1310
_comp_compgen_help()
1284
1311
{
1285
1312
(($# )) || set -- -- --help
@@ -1311,6 +1338,7 @@ _comp_compgen_help()
1311
1338
# When no arguments are specified, `--usage` is assumed.
1312
1339
#
1313
1340
# @var[in] comp_args[0]
1341
+ # @since 2.12
1314
1342
_comp_compgen_usage ()
1315
1343
{
1316
1344
(( $# )) || set -- -- --usage
@@ -1493,6 +1521,7 @@ _ncpus()
1493
1521
# @return False (1) if completion needs further processing,
1494
1522
# True (0) if tilde is followed by a valid username, completions are
1495
1523
# put in COMPREPLY and no further processing is necessary.
1524
+ # @since 2.12
1496
1525
_comp_compgen_tilde ()
1497
1526
{
1498
1527
if [[ ${cur-} == \~ * && $cur != * /* ]]; then
@@ -1848,6 +1877,7 @@ _allowed_groups()
1848
1877
fi
1849
1878
}
1850
1879
1880
+ # @since 2.12
1851
1881
_comp_selinux_users ()
1852
1882
{
1853
1883
_comp_compgen -a -- -W ' $(
@@ -1896,6 +1926,7 @@ _fstypes()
1896
1926
# see `_comp_realcommand` for those.
1897
1927
# @param $1 The file
1898
1928
# @var[out] ret The path
1929
+ # @since 2.12
1899
1930
_comp_abspath ()
1900
1931
{
1901
1932
ret=$1
@@ -1916,6 +1947,7 @@ _comp_abspath()
1916
1947
# @param $1 Command
1917
1948
# @var[out] ret Resulting string
1918
1949
# @return True (0) if command found, False (> 0) if not.
1950
+ # @since 2.12
1919
1951
_comp_realcommand ()
1920
1952
{
1921
1953
ret=" "
@@ -2367,6 +2399,7 @@ _comp__find_original_word()
2367
2399
# first complete on a command, then complete according to that command's own
2368
2400
# completion definition.
2369
2401
#
2402
+ # @since 2.12
2370
2403
_comp_command_offset ()
2371
2404
{
2372
2405
# rewrite current completion context before invoking
@@ -2484,6 +2517,7 @@ _comp_command_offset()
2484
2517
# Only intended to be used as a completion function directly associated
2485
2518
# with a command, not to be invoked from within other completion functions.
2486
2519
#
2520
+ # @since 2.12
2487
2521
_comp_command ()
2488
2522
{
2489
2523
# We unset the shell variable `words` locally to tell
@@ -2507,6 +2541,7 @@ _comp_command()
2507
2541
complete -F _comp_command aoss command " do" else eval exec ltrace nice nohup padsp \
2508
2542
" then" time tsocks vsound xargs
2509
2543
2544
+ # @since 2.12
2510
2545
_comp_root_command ()
2511
2546
{
2512
2547
local PATH=$PATH :/sbin:/usr/sbin:/usr/local/sbin
@@ -2522,6 +2557,7 @@ _complete_as_root()
2522
2557
[[ $EUID -eq 0 || ${root_command-} ]]
2523
2558
}
2524
2559
2560
+ # @since 2.12
2525
2561
_comp_longopt ()
2526
2562
{
2527
2563
local cur prev words cword was_split comp_args
@@ -2841,6 +2877,7 @@ _completion_loader()
2841
2877
# `_comp_xfunc_${1//[^a-zA-Z0-9_]/_}_$2' is used for the actual name of the
2842
2878
# shell function.
2843
2879
# @param $3... if any, specifies the arguments that are passed to the xfunc.
2880
+ # @since 2.12
2844
2881
_comp_xfunc ()
2845
2882
{
2846
2883
local xfunc_name=$2
0 commit comments