Skip to content

Commit 9a387d1

Browse files
committed
refactor: ground work for shipping depreated things in a separate file
#537 (reply in thread)
1 parent 8a34543 commit 9a387d1

File tree

4 files changed

+137
-137
lines changed

4 files changed

+137
-137
lines changed

Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pkgdata_DATA = bash_completion
44

55
# Empty, but here just to get the compat dir created with install
66
compatdir = $(sysconfdir)/bash_completion.d
7-
compat_DATA =
7+
compat_DATA = bash_completion.d/000_bash_completion_compat
88

99
profiledir = $(sysconfdir)/profile.d
1010
profile_DATA = bash_completion.sh
@@ -31,7 +31,8 @@ CLEANFILES = bash_completion.sh bash-completion.pc \
3131
EXTRA_DIST = CHANGELOG.md $(pkgdata_DATA) bash_completion.sh.in .dir-locals.el \
3232
.editorconfig README.md CONTRIBUTING.md pyproject.toml .perltidyrc \
3333
.shellcheckrc bash-completion.pc.in bash-completion-config.cmake.in \
34-
bash-completion-config-version.cmake.in setup-symlinks.sh
34+
bash-completion-config-version.cmake.in setup-symlinks.sh \
35+
$(compat_DATA)
3536

3637
install-data-hook:
3738
tmpfile=`mktemp $${TMPDIR:-/tmp}/bash_completion.XXXXXX` && \

bash_completion

Lines changed: 0 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ _comp_userland()
9898
[[ $userland == "$1" ]]
9999
}
100100

101-
_comp_deprecate_func _userland _comp_userland
102-
103101
# This function sets correct SysV init directories
104102
#
105103
_comp_sysvdirs()
@@ -112,8 +110,6 @@ _comp_sysvdirs()
112110
return 0
113111
}
114112

115-
_comp_deprecate_func _sysvdirs _comp_sysvdirs
116-
117113
# This function checks whether we have a given program on the system.
118114
#
119115
_comp_have_command()
@@ -123,18 +119,6 @@ _comp_have_command()
123119
PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type "$1" &>/dev/null
124120
}
125121

126-
_comp_deprecate_func _have _comp_have_command
127-
128-
# Backwards compatibility for compat completions that use have().
129-
# @deprecated should no longer be used; generally not needed with dynamically
130-
# loaded completions, and _comp_have_command is suitable for runtime use.
131-
# shellcheck disable=SC2317 # available at load time only
132-
have()
133-
{
134-
unset -v have
135-
_comp_have_command "$1" && have=yes
136-
}
137-
138122
# This function checks whether a given readline variable
139123
# is `on'.
140124
#
@@ -143,8 +127,6 @@ _comp_readline_variable_on()
143127
[[ $(bind -v) == *$1+([[:space:]])on* ]]
144128
}
145129

146-
_comp_deprecate_func _rl_enabled _comp_readline_variable_on
147-
148130
# This function shell-quotes the argument
149131
# @param $1 String to be quoted
150132
# @var[out] ret Resulting string
@@ -153,15 +135,6 @@ _comp_quote()
153135
ret=\'${1//\'/\'\\\'\'}\'
154136
}
155137

156-
# This function shell-quotes the argument
157-
# @deprecated Use `_comp_quote` instead. Note that `_comp_quote` stores
158-
# the results in the variable `ret` instead of writing them to stdout.
159-
quote()
160-
{
161-
local quoted=${1//\'/\'\\\'\'}
162-
printf "'%s'" "$quoted"
163-
}
164-
165138
# @see _quote_readline_by_ref()
166139
quote_readline()
167140
{
@@ -231,18 +204,6 @@ _comp_dequote()
231204
eval "ret=($1)" 2>/dev/null # may produce failglob
232205
}
233206

234-
# This function shell-dequotes the argument
235-
# @deprecated Use `_comp_dequote' instead. Note that `_comp_dequote` stores
236-
# the results in the array `ret` instead of writing them to stdout.
237-
dequote()
238-
{
239-
local ret
240-
_comp_dequote "$1"
241-
local rc=$?
242-
printf %s "$ret"
243-
return $rc
244-
}
245-
246207
# Unset the given variables across a scope boundary. Useful for unshadowing
247208
# global scoped variables. Note that simply calling unset on a local variable
248209
# will not unshadow the global variable. Rather, the result will be a local
@@ -260,29 +221,6 @@ _comp_unlocal()
260221
fi
261222
}
262223

263-
# Assign variable one scope above the caller
264-
# Usage: local "$1" && _upvar $1 "value(s)"
265-
# @param $1 Variable name to assign value to
266-
# @param $* Value(s) to assign. If multiple values, an array is
267-
# assigned, otherwise a single value is assigned.
268-
# NOTE: For assigning multiple variables, use '_upvars'. Do NOT
269-
# use multiple '_upvar' calls, since one '_upvar' call might
270-
# reassign a variable to be used by another '_upvar' call.
271-
# @see https://fvue.nl/wiki/Bash:_Passing_variables_by_reference
272-
_upvar()
273-
{
274-
echo "bash_completion: $FUNCNAME: deprecated function," \
275-
"use _upvars instead" >&2
276-
if unset -v "$1"; then # Unset & validate varname
277-
# shellcheck disable=SC2140 # TODO
278-
if (($# == 2)); then
279-
eval "$1"=\"\$2\" # Return single value
280-
else
281-
eval "$1"=\(\"\$"{@:2}"\"\) # Return array
282-
fi
283-
fi
284-
}
285-
286224
# Assign variables one scope above the caller
287225
# Usage: local varname [varname ...] &&
288226
# _upvars [-v varname value] | [-aN varname [value ...]] ...
@@ -648,66 +586,6 @@ _get_comp_words_by_ref()
648586
((${#upvars[@]})) && local "${upvars[@]}" && _upvars "${upargs[@]}"
649587
}
650588

651-
# Get the word to complete.
652-
# This is nicer than ${COMP_WORDS[COMP_CWORD]}, since it handles cases
653-
# where the user is completing in the middle of a word.
654-
# (For example, if the line is "ls foobar",
655-
# and the cursor is here --------> ^
656-
# @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be
657-
# considered word breaks. This is useful for things like scp where
658-
# we want to return host:path and not only path, so we would pass the
659-
# colon (:) as $1 in this case.
660-
# @param $2 integer Index number of word to return, negatively offset to the
661-
# current word (default is 0, previous is 1), respecting the exclusions
662-
# given at $1. For example, `_get_cword "=:" 1' returns the word left of
663-
# the current word, respecting the exclusions "=:".
664-
# @deprecated Use `_get_comp_words_by_ref cur' instead
665-
# @see _get_comp_words_by_ref()
666-
_get_cword()
667-
{
668-
local LC_CTYPE=C
669-
local cword words
670-
__reassemble_comp_words_by_ref "${1-}" words cword
671-
672-
# return previous word offset by $2
673-
if [[ ${2-} && ${2//[^0-9]/} ]]; then
674-
printf "%s" "${words[cword - $2]}"
675-
elif ((${#words[cword]} == 0 && COMP_POINT == ${#COMP_LINE})); then
676-
: # nothing
677-
else
678-
local i
679-
local cur=$COMP_LINE
680-
local index=$COMP_POINT
681-
for ((i = 0; i <= cword; ++i)); do
682-
# Current word fits in $cur, and $cur doesn't match cword?
683-
while [[ ${#cur} -ge ${#words[i]} &&
684-
${cur:0:${#words[i]}} != "${words[i]}" ]]; do
685-
# Strip first character
686-
cur=${cur:1}
687-
# Decrease cursor position, staying >= 0
688-
((index > 0)) && ((index--))
689-
done
690-
691-
# Does found word match cword?
692-
if ((i < cword)); then
693-
# No, cword lies further;
694-
local old_size=${#cur}
695-
cur=${cur#"${words[i]}"}
696-
local new_size=${#cur}
697-
((index -= old_size - new_size))
698-
fi
699-
done
700-
701-
if [[ ${words[cword]:0:${#cur}} != "$cur" ]]; then
702-
# We messed up! At least return the whole word so things
703-
# keep working
704-
printf "%s" "${words[cword]}"
705-
else
706-
printf "%s" "${cur:0:index}"
707-
fi
708-
fi
709-
} # _get_cword()
710-
711589
# Get word previous to the current word.
712590
# This is a good alternative to `prev=${COMP_WORDS[COMP_CWORD-1]}' because bash4
713591
# will properly return the previous word with respect to any given exclusions to
@@ -1127,7 +1005,6 @@ _comp_initialize()
11271005

11281006
return 0
11291007
}
1130-
_comp_deprecate_func _init_completion _comp_initialize
11311008

11321009
# Helper function for _parse_help and _parse_usage.
11331010
# @return True (0) if an option was found, False (> 0) otherwise
@@ -1582,10 +1459,6 @@ _gids()
15821459
#
15831460
_comp_backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
15841461

1585-
# @deprecated Use the variable `_comp_backup_glob` instead. This is the
1586-
# backward-compatibility name.
1587-
_backup_glob=$_comp_backup_glob
1588-
15891462
# Complete on xinetd services
15901463
#
15911464
_xinetd_services()
@@ -2387,7 +2260,6 @@ _comp_command_offset()
23872260
done
23882261
fi
23892262
}
2390-
_comp_deprecate_func _command_offset _comp_command_offset
23912263

23922264
# A _comp_command_offset wrapper function for use when the offset is unknown.
23932265
# Only intended to be used as a completion function directly associated
@@ -2407,7 +2279,6 @@ _comp_command()
24072279
done
24082280
_comp_command_offset $offset
24092281
}
2410-
_comp_deprecate_func _command _comp_command
24112282
complete -F _comp_command aoss command "do" else eval exec ltrace nice nohup padsp \
24122283
"then" time tsocks vsound xargs
24132284

@@ -2417,7 +2288,6 @@ _comp_root_command()
24172288
local root_command=$1
24182289
_comp_command
24192290
}
2420-
_comp_deprecate_func _root_command _comp_root_command
24212291
complete -F _comp_root_command fakeroot gksu gksudo kdesudo really
24222292

24232293
# Return true if the completion should be treated as running as root
@@ -2739,8 +2609,6 @@ _comp_xfunc()
27392609
"$xfunc_name" "${@:3}"
27402610
}
27412611
2742-
_comp_deprecate_func _xfunc _comp_xfunc
2743-
27442612
# source compat completion directory definitions
27452613
_comp__init_compat_dir=${BASH_COMPLETION_COMPAT_DIR:-/etc/bash_completion.d}
27462614
if [[ -d $_comp__init_compat_dir && -r $_comp__init_compat_dir && -x $_comp__init_compat_dir ]]; then
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Deprecated bash_completion functions and variables -*- shell-script -*-
2+
3+
_comp_deprecate_func _userland _comp_userland
4+
_comp_deprecate_func _sysvdirs _comp_sysvdirs
5+
_comp_deprecate_func _have _comp_have_command
6+
_comp_deprecate_func _rl_enabled _comp_readline_variable_on
7+
_comp_deprecate_func _init_completion _comp_initialize
8+
_comp_deprecate_func _command_offset _comp_command_offset
9+
_comp_deprecate_func _command _comp_command
10+
_comp_deprecate_func _root_command _comp_root_command
11+
_comp_deprecate_func _xfunc _comp_xfunc
12+
13+
# Backwards compatibility for compat completions that use have().
14+
# @deprecated should no longer be used; generally not needed with dynamically
15+
# loaded completions, and _comp_have_command is suitable for
16+
# runtime use.
17+
# shellcheck disable=SC2317 # available at load time only
18+
have()
19+
{
20+
unset -v have
21+
_comp_have_command "$1" && have=yes
22+
}
23+
24+
# This function shell-quotes the argument
25+
# @deprecated Use `_comp_quote` instead. Note that `_comp_quote` stores
26+
# the results in the variable `ret` instead of writing them to stdout.
27+
quote()
28+
{
29+
local quoted=${1//\'/\'\\\'\'}
30+
printf "'%s'" "$quoted"
31+
}
32+
33+
# This function shell-dequotes the argument
34+
# @deprecated Use `_comp_dequote' instead. Note that `_comp_dequote` stores
35+
# the results in the array `ret` instead of writing them to stdout.
36+
dequote()
37+
{
38+
local ret
39+
_comp_dequote "$1"
40+
local rc=$?
41+
printf %s "$ret"
42+
return $rc
43+
}
44+
45+
# Assign variable one scope above the caller
46+
# Usage: local "$1" && _upvar $1 "value(s)"
47+
# @param $1 Variable name to assign value to
48+
# @param $* Value(s) to assign. If multiple values, an array is
49+
# assigned, otherwise a single value is assigned.
50+
# NOTE: For assigning multiple variables, use '_upvars'. Do NOT
51+
# use multiple '_upvar' calls, since one '_upvar' call might
52+
# reassign a variable to be used by another '_upvar' call.
53+
# @see https://fvue.nl/wiki/Bash:_Passing_variables_by_reference
54+
_upvar()
55+
{
56+
echo "bash_completion: $FUNCNAME: deprecated function," \
57+
"use _upvars instead" >&2
58+
if unset -v "$1"; then # Unset & validate varname
59+
# shellcheck disable=SC2140 # TODO
60+
if (($# == 2)); then
61+
eval "$1"=\"\$2\" # Return single value
62+
else
63+
eval "$1"=\(\"\$"{@:2}"\"\) # Return array
64+
fi
65+
fi
66+
}
67+
68+
# Get the word to complete.
69+
# This is nicer than ${COMP_WORDS[COMP_CWORD]}, since it handles cases
70+
# where the user is completing in the middle of a word.
71+
# (For example, if the line is "ls foobar",
72+
# and the cursor is here --------> ^
73+
# @param $1 string Characters out of $COMP_WORDBREAKS which should NOT be
74+
# considered word breaks. This is useful for things like scp where
75+
# we want to return host:path and not only path, so we would pass the
76+
# colon (:) as $1 in this case.
77+
# @param $2 integer Index number of word to return, negatively offset to the
78+
# current word (default is 0, previous is 1), respecting the exclusions
79+
# given at $1. For example, `_get_cword "=:" 1' returns the word left of
80+
# the current word, respecting the exclusions "=:".
81+
# @deprecated Use `_get_comp_words_by_ref cur' instead
82+
# @see _get_comp_words_by_ref()
83+
_get_cword()
84+
{
85+
local LC_CTYPE=C
86+
local cword words
87+
__reassemble_comp_words_by_ref "${1-}" words cword
88+
89+
# return previous word offset by $2
90+
if [[ ${2-} && ${2//[^0-9]/} ]]; then
91+
printf "%s" "${words[cword - $2]}"
92+
elif ((${#words[cword]} == 0 && COMP_POINT == ${#COMP_LINE})); then
93+
: # nothing
94+
else
95+
local i
96+
local cur=$COMP_LINE
97+
local index=$COMP_POINT
98+
for ((i = 0; i <= cword; ++i)); do
99+
# Current word fits in $cur, and $cur doesn't match cword?
100+
while [[ ${#cur} -ge ${#words[i]} &&
101+
${cur:0:${#words[i]}} != "${words[i]}" ]]; do
102+
# Strip first character
103+
cur=${cur:1}
104+
# Decrease cursor position, staying >= 0
105+
((index > 0)) && ((index--))
106+
done
107+
108+
# Does found word match cword?
109+
if ((i < cword)); then
110+
# No, cword lies further;
111+
local old_size=${#cur}
112+
cur=${cur#"${words[i]}"}
113+
local new_size=${#cur}
114+
((index -= old_size - new_size))
115+
fi
116+
done
117+
118+
if [[ ${words[cword]:0:${#cur}} != "$cur" ]]; then
119+
# We messed up! At least return the whole word so things
120+
# keep working
121+
printf "%s" "${words[cword]}"
122+
else
123+
printf "%s" "${cur:0:index}"
124+
fi
125+
fi
126+
} # _get_cword()
127+
128+
# @deprecated Use the variable `_comp_backup_glob` instead. This is the
129+
# backward-compatibility name.
130+
_backup_glob=$_comp_backup_glob
131+
132+
# ex: filetype=sh

0 commit comments

Comments
 (0)