Skip to content

Commit 8181dab

Browse files
authored
Merge pull request scop#678 from scop/refactor/variable-renames
refactor: public config variable naming changes
2 parents 1ae8434 + a2a1459 commit 8181dab

File tree

10 files changed

+80
-66
lines changed

10 files changed

+80
-66
lines changed

bash_completion

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ _filedir()
623623
# the fallback condition with the "plus" dirs.
624624
local opts=(-f -X "$xspec")
625625
[[ $xspec ]] && plusdirs=(-o plusdirs)
626-
[[ ${COMP_FILEDIR_FALLBACK-} || -z ${plusdirs-} ]] ||
626+
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} ||
627+
-z ${plusdirs-} ]] ||
627628
opts+=("${plusdirs[@]}")
628629

629630
reset=$(shopt -po noglob)
@@ -634,7 +635,8 @@ _filedir()
634635
IFS=$'\n'
635636

636637
# Try without filter if it failed to produce anything and configured to
637-
[[ -n ${COMP_FILEDIR_FALLBACK-} && -n $arg && ${#toks[@]} -lt 1 ]] && {
638+
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
639+
-n $arg && ${#toks[@]} -lt 1 ]] && {
638640
reset=$(shopt -po noglob)
639641
set -o noglob
640642
toks+=($(compgen -f ${plusdirs+"${plusdirs[@]}"} -- $quoted))
@@ -1350,7 +1352,7 @@ _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
13501352
#
13511353
_xinetd_services()
13521354
{
1353-
local xinetddir=${BASHCOMP_XINETDDIR:-/etc/xinetd.d}
1355+
local xinetddir=${_comp__test_xinetd_dir:-/etc/xinetd.d}
13541356
if [[ -d $xinetddir ]]; then
13551357
local IFS=$' \t\n' reset=$(shopt -p nullglob)
13561358
shopt -s nullglob
@@ -1754,9 +1756,9 @@ _included_ssh_config_files()
17541756
# Helper function for completing _known_hosts.
17551757
# This function performs host completion based on ssh's config and known_hosts
17561758
# files, as well as hostnames reported by avahi-browse if
1757-
# COMP_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value. Also hosts from
1758-
# HOSTFILE (compgen -A hostname) are added, unless
1759-
# COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
1759+
# BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value.
1760+
# Also hosts from HOSTFILE (compgen -A hostname) are added, unless
1761+
# BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
17601762
# Usage: _known_hosts_real [OPTIONS] CWORD
17611763
# Options: -a Use aliases from ssh config files
17621764
# -c Use `:' suffix
@@ -1927,7 +1929,7 @@ _known_hosts_real()
19271929
fi
19281930

19291931
# Add hosts reported by avahi-browse, if desired and it's available.
1930-
if [[ ${COMP_KNOWN_HOSTS_WITH_AVAHI-} ]] &&
1932+
if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI-${COMP_KNOWN_HOSTS_WITH_AVAHI-}} ]] &&
19311933
type avahi-browse &>/dev/null; then
19321934
# Some old versions of avahi-browse reportedly didn't have -k
19331935
# (even if mentioned in the manpage); those we do not support any more.
@@ -1945,8 +1947,8 @@ _known_hosts_real()
19451947
fi
19461948

19471949
# Add results of normal hostname completion, unless
1948-
# `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
1949-
if [[ -n ${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} ]]; then
1950+
# `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
1951+
if [[ -n ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
19501952
COMPREPLY+=(
19511953
$(compgen -A hostname -P "$prefix" -S "$suffix" -- "$cur"))
19521954
fi
@@ -2267,7 +2269,8 @@ _filedir_xspec()
22672269
))
22682270
22692271
# Try without filter if it failed to produce anything and configured to
2270-
[[ -n ${COMP_FILEDIR_FALLBACK:-} && ${#toks[@]} -lt 1 ]] && {
2272+
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
2273+
${#toks[@]} -lt 1 ]] && {
22712274
local reset=$(shopt -po noglob)
22722275
set -o noglob
22732276
toks+=($(compgen -f -- "$(quote_readline "$cur")"))

completions/configure

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ _configure()
2525
return
2626
fi
2727

28-
# if $COMP_CONFIGURE_HINTS is not null, then completions of the form
29-
# --option=SETTING will include 'SETTING' as a contextual hint
30-
if [[ ${COMP_CONFIGURE_HINTS-} ]]; then
28+
# if $BASH_COMPLETION_CMD_CONFIGURE_HINTS is not null, then completions of
29+
# the form --option=SETTING will include 'SETTING' as a contextual hint
30+
if [[ ${BASH_COMPLETION_CMD_CONFIGURE_HINTS-${COMP_CONFIGURE_HINTS-}} ]]; then
3131
COMPREPLY=($(compgen -W "$($1 --help 2>&1 |
3232
awk '/^ --[A-Za-z]/ { print $1; \
3333
if ($2 ~ /--[A-Za-z]/) print $2 }' | command sed -e 's/[[,].*//g')" \

completions/cvs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ _cvs()
248248
esac
249249

250250
if [[ $cur != -* ]]; then
251-
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will
252-
# complete on remotely checked-out files (requires
251+
# if $BASH_COMPLETION_CMD_CVS_REMOTE is not null, 'cvs commit'
252+
# will complete on remotely checked-out files (requires
253253
# passwordless access to the remote repository
254-
if [[ -n ${COMP_CVS_REMOTE:-} ]]; then
254+
if [[ -n ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
255255
# this is the least computationally intensive way found so
256256
# far, but other changes (something other than
257257
# changed/removed/new) may be missing

completions/iwconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _iwconfig()
1313
;;
1414
essid)
1515
COMPREPLY=($(compgen -W 'on off any' -- "$cur"))
16-
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
16+
if [[ ${BASH_COMPLETION_CMD_IWCONFIG_SCAN-${COMP_IWLIST_SCAN-}} ]]; then
1717
COMPREPLY+=($(compgen -W \
1818
"$(iwlist ${words[1]} scan |
1919
awk -F'\"' '/ESSID/ {print $2}')" -- "$cur"))
@@ -37,7 +37,7 @@ _iwconfig()
3737
;;
3838
ap)
3939
COMPREPLY=($(compgen -W 'on off any' -- "$cur"))
40-
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
40+
if [[ ${BASH_COMPLETION_CMD_IWCONFIG_SCAN-${COMP_IWLIST_SCAN-}} ]]; then
4141
COMPREPLY+=($(compgen -W \
4242
"$(iwlist ${words[1]} scan |
4343
awk -F ': ' '/Address/ {print $2}')" -- "$cur"))

completions/tar

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
# It's more important to have proper completion of paths to tar files than it
5454
# is to have completion for their contents, so this sacrifice was made and
5555
# `-o filenames` is used with complete instead by default. Setting the
56-
# `$COMP_TAR_INTERNAL_PATHS` environment variable to a non-null
56+
# `$BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS` environment variable to a non-null
5757
# value *before sourcing* this completion toggles that the other way around.
5858

5959
__gtar_parse_help_opt()
@@ -499,7 +499,7 @@ _gtar()
499499
# FIXME: handle long options
500500
local tar_mode_arg=
501501

502-
if [[ -v BASHCOMP_TAR_OPT_DEBUG ]]; then
502+
if [[ -v _comp_cmd_tar__debug ]]; then
503503
set -x
504504
local PS4='$BASH_SOURCE:$LINENO: '
505505
fi
@@ -652,7 +652,7 @@ _gtar()
652652
break
653653
done # just-for-easy-break while
654654

655-
if [[ -v BASHCOMP_TAR_OPT_DEBUG ]]; then
655+
if [[ -v _comp_cmd_tar__debug ]]; then
656656
set +x
657657
fi
658658
}
@@ -732,15 +732,15 @@ _tar()
732732
$func "$@"
733733

734734
# Install real completion for subsequent completions
735-
if [[ ${COMP_TAR_INTERNAL_PATHS-} ]]; then
735+
if [[ ${BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS-${COMP_TAR_INTERNAL_PATHS-}} ]]; then
736736
complete -F $func -o dirnames tar
737737
else
738738
complete -F $func tar
739739
fi
740740
unset -f _tar
741741
}
742742

743-
if [[ ${COMP_TAR_INTERNAL_PATHS-} ]]; then
743+
if [[ ${BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS-${COMP_TAR_INTERNAL_PATHS-}} ]]; then
744744
complete -F _tar -o dirnames tar
745745
complete -F _gtar -o dirnames gtar
746746
complete -F _posix_tar -o dirnames bsdtar

doc/configuration.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,19 @@ completion files that are loaded eagerly from `bash_completion` when it is
2525
loaded. If unset or null, the default compatibility directory to use is
2626
`/etc/bash_completion.d`.
2727

28-
### `COMP_CONFIGURE_HINTS`
29-
30-
If set and not null, `configure` completion will return the entire option
31-
string (e.g. `--this-option=DESCRIPTION`) so one can see what kind of data
32-
is required and then simply delete the descriptive text and add one's own
33-
data. If unset or null (default), `configure` completion will strip
34-
everything after the `=` when returning completions.
35-
36-
### `COMP_CVS_REMOTE`
37-
38-
If set and not null, `cvs commit` completion will try to complete on
39-
remotely checked-out files. This requires passwordless access to the
40-
remote repository. Default is unset.
41-
42-
### `COMP_FILEDIR_FALLBACK`
28+
### `BASH_COMPLETION_FILEDIR_FALLBACK`
4329

4430
If set and not null, completions that look for filenames based on their
4531
"extensions" will fall back to suggesting all files if there are none
4632
matching the sought ones.
4733

48-
### `COMP_IWLIST_SCAN`
34+
### `BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI`
4935

50-
If set and not null, `iwconfig` completion will try to complete on
51-
available wireless networks identifiers. Default is unset.
36+
If set and not null, known hosts completion will try to use `avahi-browse`
37+
for additional completions. This may be a slow operation in some setups.
38+
Default is unset.
5239

53-
### `COMP_KNOWN_HOSTS_WITH_HOSTFILE`
40+
### `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE`
5441

5542
If set and not null (default), known hosts completion will complement
5643
hostnames from ssh's known_hosts files with hostnames taken from the file
@@ -59,13 +46,26 @@ known hosts completion will omit hostnames from `HOSTFILE`. Omitting
5946
hostnames from `HOSTFILE` is useful if `HOSTFILE` contains many entries for
6047
local web development or ad-blocking.
6148

62-
### `COMP_KNOWN_HOSTS_WITH_AVAHI`
49+
### `BASH_COMPLETION_CMD_CONFIGURE_HINTS`
6350

64-
If set and not null, known hosts completion will try to use `avahi-browse`
65-
for additional completions. This may be a slow operation in some setups.
66-
Default is unset.
51+
If set and not null, `configure` completion will return the entire option
52+
string (e.g. `--this-option=DESCRIPTION`) so one can see what kind of data
53+
is required and then simply delete the descriptive text and add one's own
54+
data. If unset or null (default), `configure` completion will strip
55+
everything after the `=` when returning completions.
56+
57+
### `BASH_COMPLETION_CMD_CVS_REMOTE`
58+
59+
If set and not null, `cvs commit` completion will try to complete on
60+
remotely checked-out files. This requires passwordless access to the
61+
remote repository. Default is unset.
62+
63+
### `BASH_COMPLETION_CMD_IWCONFIG_SCAN`
64+
65+
If set and not null, `iwconfig` completion will try to complete on
66+
available wireless networks identifiers. Default is unset.
6767

68-
### `COMP_TAR_INTERNAL_PATHS`
68+
### `BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS`
6969

7070
If set and not null _before sourcing_ the `tar` completion, it will do
7171
correct path completion for tar file _contents_. If unset or null,

test/config/bashrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,16 @@ export XDG_DATA_DIRS=/var/empty
4545

4646
# Make sure default settings are in effect
4747
unset -v \
48+
BASH_COMPLETION_CMD_CONFIGURE_HINTS \
49+
BASH_COMPLETION_CMD_CVS_REMOTE \
50+
BASH_COMPLETION_CMD_IWCONFIG_SCAN \
51+
BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS \
52+
BASH_COMPLETION_FILEDIR_FALLBACK \
53+
BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE \
4854
COMP_CONFIGURE_HINTS \
4955
COMP_CVS_REMOTE \
56+
COMP_FILEDIR_FALLBACK \
57+
COMP_IWLIST_SCAN \
5058
COMP_KNOWN_HOSTS_WITH_HOSTFILE \
5159
COMP_TAR_INTERNAL_PATHS
5260

test/t/conftest.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ def bash(request) -> pexpect.spawn:
191191
tmpdir = None
192192
bash = None
193193

194-
if os.environ.get("BASHCOMP_TEST_LOGFILE"):
195-
logfile = open(os.environ["BASHCOMP_TEST_LOGFILE"], "w")
194+
if os.environ.get("BASH_COMPLETION_TEST_LOGFILE"):
195+
logfile = open(os.environ["BASH_COMPLETION_TEST_LOGFILE"], "w")
196196
elif os.environ.get("CI"):
197197
logfile = sys.stdout
198198

@@ -256,8 +256,10 @@ def bash(request) -> pexpect.spawn:
256256

257257
# Start bash
258258
bash = pexpect.spawn(
259-
"%s --norc" % os.environ.get("BASHCOMP_TEST_BASH", "bash"),
260-
maxread=os.environ.get("BASHCOMP_TEST_PEXPECT_MAXREAD", 20000),
259+
"%s --norc" % os.environ.get("BASH_COMPLETION_TEST_BASH", "bash"),
260+
maxread=os.environ.get(
261+
"BASH_COMPLETION_TEST_PEXPECT_MAXREAD", 20000
262+
),
261263
logfile=logfile,
262264
cwd=cwd,
263265
env=env,
@@ -444,7 +446,7 @@ class bash_env_saved:
444446

445447
def __init__(self, bash: pexpect.spawn, sendintr: bool = False):
446448
bash_env_saved.counter += 1
447-
self.prefix: str = "_BASHCOMP_TEST%d" % bash_env_saved.counter
449+
self.prefix: str = "_comp__test_%d" % bash_env_saved.counter
448450

449451
self.bash = bash
450452
self.cwd_changed: bool = False
@@ -655,7 +657,7 @@ def diff_env(before: List[str], after: List[str], ignore: str):
655657
if not re.search(r"^(---|\+\+\+|@@ )", x)
656658
# Ignore variables expected to change:
657659
and not re.search(
658-
r"^[-+](_|PPID|BASH_REMATCH|_BASHCOMP_TEST\w+)=",
660+
r"^[-+](_|PPID|BASH_REMATCH|_comp__test_\d+_\w+)=",
659661
x,
660662
re.ASCII,
661663
)

test/t/unit/test_unit_known_hosts_real.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@pytest.mark.bashcomp(
99
cmd=None,
10-
ignore_env="^[+-](COMP(REPLY|_KNOWN_HOSTS_WITH_HOSTFILE))=",
10+
ignore_env="^[+-](COMPREPLY|BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE)=",
1111
)
1212
class TestUnitKnownHostsReal:
1313
@pytest.mark.parametrize(
@@ -43,9 +43,9 @@ def test_basic(
4343
)
4444
assert_bash_exec(
4545
bash,
46-
"unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE"
46+
"unset -v BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE"
4747
if hostfile
48-
else "COMP_KNOWN_HOSTS_WITH_HOSTFILE=",
48+
else "BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE=",
4949
)
5050
output = assert_bash_exec(
5151
bash,
@@ -66,11 +66,12 @@ def test_basic(
6666
)
6767
def test_ip_filtering(self, bash, family, result):
6868
assert_bash_exec(
69-
bash, "unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE"
69+
bash,
70+
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE",
7071
)
7172
output = assert_bash_exec(
7273
bash,
73-
"COMP_KNOWN_HOSTS_WITH_HOSTFILE= "
74+
"BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE= "
7475
"_known_hosts_real -%sF _known_hosts_real/localhost_config ''; "
7576
r'printf "%%s\n" "${COMPREPLY[@]}"' % family,
7677
want_output=True,
@@ -88,7 +89,7 @@ def test_consecutive_spaces(self, bash, hosts):
8889

8990
output = assert_bash_exec(
9091
bash,
91-
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
92+
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE; "
9293
"_known_hosts_real -aF '_known_hosts_real/spaced conf' ''; "
9394
r'printf "%s\n" "${COMPREPLY[@]}"',
9495
want_output=True,
@@ -108,8 +109,8 @@ def test_files_starting_with_tilde(self, bash, hosts):
108109
bash_env.write_variable("HOME", bash.cwd)
109110
output = assert_bash_exec(
110111
bash,
111-
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
112-
"_known_hosts_real -aF _known_hosts_real/config_tilde ''; "
112+
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
113+
" _known_hosts_real -aF _known_hosts_real/config_tilde ''; "
113114
r'printf "%s\n" "${COMPREPLY[@]}"',
114115
want_output=True,
115116
)
@@ -131,8 +132,8 @@ def test_included_configs(self, bash, hosts):
131132
bash_env.write_variable("HOME", "%s/_known_hosts_real" % bash.cwd)
132133
output = assert_bash_exec(
133134
bash,
134-
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
135-
"_known_hosts_real -aF _known_hosts_real/config_include ''; "
135+
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
136+
" _known_hosts_real -aF _known_hosts_real/config_include ''; "
136137
r'printf "%s\n" "${COMPREPLY[@]}"',
137138
want_output=True,
138139
)
@@ -144,8 +145,8 @@ def test_no_globbing(self, bash):
144145
bash_env.chdir("_known_hosts_real")
145146
output = assert_bash_exec(
146147
bash,
147-
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
148-
"_known_hosts_real -aF config ''; "
148+
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
149+
" _known_hosts_real -aF config ''; "
149150
r'printf "%s\n" "${COMPREPLY[@]}"',
150151
want_output=True,
151152
)

test/t/unit/test_unit_xinetd_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_env_non_pollution(self, bash):
1717
def test_basic(self, bash):
1818
output = assert_bash_exec(
1919
bash,
20-
"foo() { local BASHCOMP_XINETDDIR=$PWD/shared/bin;unset -v COMPREPLY; "
20+
"foo() { local _comp__test_xinetd_dir=$PWD/shared/bin; unset -v COMPREPLY; "
2121
'_xinetd_services; printf "%s\\n" "${COMPREPLY[@]}"; }; foo; unset -f foo',
2222
want_output=True,
2323
)

0 commit comments

Comments
 (0)