Skip to content

refactor: public config variable naming changes #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@ _filedir()
# the fallback condition with the "plus" dirs.
local opts=(-f -X "$xspec")
[[ $xspec ]] && plusdirs=(-o plusdirs)
[[ ${COMP_FILEDIR_FALLBACK-} || -z ${plusdirs-} ]] ||
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} ||
-z ${plusdirs-} ]] ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-z ${plusdirs-} ]] ||
! ${plusdirs-} ]] ||

It seems there are more cases [[ ! $word ]] (5 cases in bash_completion) than [[ -z $word ]] (2 cases). Another instance of -z is in line bash_completion:1990 (_cd).

opts+=("${plusdirs[@]}")

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

# Try without filter if it failed to produce anything and configured to
[[ -n ${COMP_FILEDIR_FALLBACK-} && -n $arg && ${#toks[@]} -lt 1 ]] && {
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
-n $arg && ${#toks[@]} -lt 1 ]] && {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-n $arg && ${#toks[@]} -lt 1 ]] && {
$arg && ${#toks[@]} -lt 1 ]] && {

reset=$(shopt -po noglob)
set -o noglob
toks+=($(compgen -f ${plusdirs+"${plusdirs[@]}"} -- $quoted))
Expand Down Expand Up @@ -1350,7 +1352,7 @@ _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
#
_xinetd_services()
{
local xinetddir=${BASHCOMP_XINETDDIR:-/etc/xinetd.d}
local xinetddir=${_comp__test_xinetd_dir:-/etc/xinetd.d}
if [[ -d $xinetddir ]]; then
local IFS=$' \t\n' reset=$(shopt -p nullglob)
shopt -s nullglob
Expand Down Expand Up @@ -1754,9 +1756,9 @@ _included_ssh_config_files()
# Helper function for completing _known_hosts.
# This function performs host completion based on ssh's config and known_hosts
# files, as well as hostnames reported by avahi-browse if
# COMP_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value. Also hosts from
# HOSTFILE (compgen -A hostname) are added, unless
# COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
# BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value.
# Also hosts from HOSTFILE (compgen -A hostname) are added, unless
# BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
# Usage: _known_hosts_real [OPTIONS] CWORD
# Options: -a Use aliases from ssh config files
# -c Use `:' suffix
Expand Down Expand Up @@ -1927,7 +1929,7 @@ _known_hosts_real()
fi

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

# Add results of normal hostname completion, unless
# `COMP_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
if [[ -n ${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1} ]]; then
# `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE' is set to an empty value.
if [[ -n ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ -n ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then
if [[ ${BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE-${COMP_KNOWN_HOSTS_WITH_HOSTFILE-1}} ]]; then

I think this is more consistent with other cases.

COMPREPLY+=(
$(compgen -A hostname -P "$prefix" -S "$suffix" -- "$cur"))
fi
Expand Down Expand Up @@ -2267,7 +2269,8 @@ _filedir_xspec()
))

# Try without filter if it failed to produce anything and configured to
[[ -n ${COMP_FILEDIR_FALLBACK:-} && ${#toks[@]} -lt 1 ]] && {
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
${#toks[@]} -lt 1 ]] && {
local reset=$(shopt -po noglob)
set -o noglob
toks+=($(compgen -f -- "$(quote_readline "$cur")"))
Expand Down
6 changes: 3 additions & 3 deletions completions/configure
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ _configure()
return
fi

# if $COMP_CONFIGURE_HINTS is not null, then completions of the form
# --option=SETTING will include 'SETTING' as a contextual hint
if [[ ${COMP_CONFIGURE_HINTS-} ]]; then
# if $BASH_COMPLETION_CMD_CONFIGURE_HINTS is not null, then completions of
# the form --option=SETTING will include 'SETTING' as a contextual hint
if [[ ${BASH_COMPLETION_CMD_CONFIGURE_HINTS-${COMP_CONFIGURE_HINTS-}} ]]; then
COMPREPLY=($(compgen -W "$($1 --help 2>&1 |
awk '/^ --[A-Za-z]/ { print $1; \
if ($2 ~ /--[A-Za-z]/) print $2 }' | command sed -e 's/[[,].*//g')" \
Expand Down
6 changes: 3 additions & 3 deletions completions/cvs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ _cvs()
esac

if [[ $cur != -* ]]; then
# if $COMP_CVS_REMOTE is not null, 'cvs commit' will
# complete on remotely checked-out files (requires
# if $BASH_COMPLETION_CMD_CVS_REMOTE is not null, 'cvs commit'
# will complete on remotely checked-out files (requires
# passwordless access to the remote repository
if [[ -n ${COMP_CVS_REMOTE:-} ]]; then
if [[ -n ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ -n ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then
if [[ ${BASH_COMPLETION_CMD_CVS_REMOTE-${COMP_CVS_REMOTE-}} ]]; then

# this is the least computationally intensive way found so
# far, but other changes (something other than
# changed/removed/new) may be missing
Expand Down
4 changes: 2 additions & 2 deletions completions/iwconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _iwconfig()
;;
essid)
COMPREPLY=($(compgen -W 'on off any' -- "$cur"))
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
if [[ ${BASH_COMPLETION_CMD_IWCONFIG_SCAN-${COMP_IWLIST_SCAN-}} ]]; then
COMPREPLY+=($(compgen -W \
"$(iwlist ${words[1]} scan |
awk -F'\"' '/ESSID/ {print $2}')" -- "$cur"))
Expand All @@ -37,7 +37,7 @@ _iwconfig()
;;
ap)
COMPREPLY=($(compgen -W 'on off any' -- "$cur"))
if [[ -n ${COMP_IWLIST_SCAN:-} ]]; then
if [[ ${BASH_COMPLETION_CMD_IWCONFIG_SCAN-${COMP_IWLIST_SCAN-}} ]]; then
COMPREPLY+=($(compgen -W \
"$(iwlist ${words[1]} scan |
awk -F ': ' '/Address/ {print $2}')" -- "$cur"))
Expand Down
10 changes: 5 additions & 5 deletions completions/tar
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# It's more important to have proper completion of paths to tar files than it
# is to have completion for their contents, so this sacrifice was made and
# `-o filenames` is used with complete instead by default. Setting the
# `$COMP_TAR_INTERNAL_PATHS` environment variable to a non-null
# `$BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS` environment variable to a non-null
# value *before sourcing* this completion toggles that the other way around.

__gtar_parse_help_opt()
Expand Down Expand Up @@ -499,7 +499,7 @@ _gtar()
# FIXME: handle long options
local tar_mode_arg=

if [[ -v BASHCOMP_TAR_OPT_DEBUG ]]; then
if [[ -v _comp_cmd_tar__debug ]]; then
set -x
local PS4='$BASH_SOURCE:$LINENO: '
fi
Expand Down Expand Up @@ -652,7 +652,7 @@ _gtar()
break
done # just-for-easy-break while

if [[ -v BASHCOMP_TAR_OPT_DEBUG ]]; then
if [[ -v _comp_cmd_tar__debug ]]; then
set +x
fi
}
Expand Down Expand Up @@ -732,15 +732,15 @@ _tar()
$func "$@"

# Install real completion for subsequent completions
if [[ ${COMP_TAR_INTERNAL_PATHS-} ]]; then
if [[ ${BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS-${COMP_TAR_INTERNAL_PATHS-}} ]]; then
complete -F $func -o dirnames tar
else
complete -F $func tar
fi
unset -f _tar
}

if [[ ${COMP_TAR_INTERNAL_PATHS-} ]]; then
if [[ ${BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS-${COMP_TAR_INTERNAL_PATHS-}} ]]; then
complete -F _tar -o dirnames tar
complete -F _gtar -o dirnames gtar
complete -F _posix_tar -o dirnames bsdtar
Expand Down
48 changes: 24 additions & 24 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,19 @@ completion files that are loaded eagerly from `bash_completion` when it is
loaded. If unset or null, the default compatibility directory to use is
`/etc/bash_completion.d`.

### `COMP_CONFIGURE_HINTS`

If set and not null, `configure` completion will return the entire option
string (e.g. `--this-option=DESCRIPTION`) so one can see what kind of data
is required and then simply delete the descriptive text and add one's own
data. If unset or null (default), `configure` completion will strip
everything after the `=` when returning completions.

### `COMP_CVS_REMOTE`

If set and not null, `cvs commit` completion will try to complete on
remotely checked-out files. This requires passwordless access to the
remote repository. Default is unset.

### `COMP_FILEDIR_FALLBACK`
### `BASH_COMPLETION_FILEDIR_FALLBACK`

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

### `COMP_IWLIST_SCAN`
### `BASH_COMPLETION_KNOWN_HOSTS_WITH_AVAHI`

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

### `COMP_KNOWN_HOSTS_WITH_HOSTFILE`
### `BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE`

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

### `COMP_KNOWN_HOSTS_WITH_AVAHI`
### `BASH_COMPLETION_CMD_CONFIGURE_HINTS`

If set and not null, known hosts completion will try to use `avahi-browse`
for additional completions. This may be a slow operation in some setups.
Default is unset.
If set and not null, `configure` completion will return the entire option
string (e.g. `--this-option=DESCRIPTION`) so one can see what kind of data
is required and then simply delete the descriptive text and add one's own
data. If unset or null (default), `configure` completion will strip
everything after the `=` when returning completions.

### `BASH_COMPLETION_CMD_CVS_REMOTE`

If set and not null, `cvs commit` completion will try to complete on
remotely checked-out files. This requires passwordless access to the
remote repository. Default is unset.

### `BASH_COMPLETION_CMD_IWCONFIG_SCAN`

If set and not null, `iwconfig` completion will try to complete on
available wireless networks identifiers. Default is unset.

### `COMP_TAR_INTERNAL_PATHS`
### `BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS`

If set and not null _before sourcing_ the `tar` completion, it will do
correct path completion for tar file _contents_. If unset or null,
Expand Down
8 changes: 8 additions & 0 deletions test/config/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ export XDG_DATA_DIRS=/var/empty

# Make sure default settings are in effect
unset -v \
BASH_COMPLETION_CMD_CONFIGURE_HINTS \
BASH_COMPLETION_CMD_CVS_REMOTE \
BASH_COMPLETION_CMD_IWCONFIG_SCAN \
BASH_COMPLETION_CMD_TAR_INTERNAL_PATHS \
BASH_COMPLETION_FILEDIR_FALLBACK \
BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE \
COMP_CONFIGURE_HINTS \
COMP_CVS_REMOTE \
COMP_FILEDIR_FALLBACK \
COMP_IWLIST_SCAN \
COMP_KNOWN_HOSTS_WITH_HOSTFILE \
COMP_TAR_INTERNAL_PATHS

Expand Down
14 changes: 8 additions & 6 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def bash(request) -> pexpect.spawn:
tmpdir = None
bash = None

if os.environ.get("BASHCOMP_TEST_LOGFILE"):
logfile = open(os.environ["BASHCOMP_TEST_LOGFILE"], "w")
if os.environ.get("BASH_COMPLETION_TEST_LOGFILE"):
logfile = open(os.environ["BASH_COMPLETION_TEST_LOGFILE"], "w")
elif os.environ.get("CI"):
logfile = sys.stdout

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

# Start bash
bash = pexpect.spawn(
"%s --norc" % os.environ.get("BASHCOMP_TEST_BASH", "bash"),
maxread=os.environ.get("BASHCOMP_TEST_PEXPECT_MAXREAD", 20000),
"%s --norc" % os.environ.get("BASH_COMPLETION_TEST_BASH", "bash"),
maxread=os.environ.get(
"BASH_COMPLETION_TEST_PEXPECT_MAXREAD", 20000
),
logfile=logfile,
cwd=cwd,
env=env,
Expand Down Expand Up @@ -444,7 +446,7 @@ class bash_env_saved:

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

self.bash = bash
self.cwd_changed: bool = False
Expand Down Expand Up @@ -655,7 +657,7 @@ def diff_env(before: List[str], after: List[str], ignore: str):
if not re.search(r"^(---|\+\+\+|@@ )", x)
# Ignore variables expected to change:
and not re.search(
r"^[-+](_|PPID|BASH_REMATCH|_BASHCOMP_TEST\w+)=",
r"^[-+](_|PPID|BASH_REMATCH|_comp__test_\d+_\w+)=",
x,
re.ASCII,
)
Expand Down
25 changes: 13 additions & 12 deletions test/t/unit/test_unit_known_hosts_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@pytest.mark.bashcomp(
cmd=None,
ignore_env="^[+-](COMP(REPLY|_KNOWN_HOSTS_WITH_HOSTFILE))=",
ignore_env="^[+-](COMPREPLY|BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE)=",
)
class TestUnitKnownHostsReal:
@pytest.mark.parametrize(
Expand Down Expand Up @@ -43,9 +43,9 @@ def test_basic(
)
assert_bash_exec(
bash,
"unset -v COMP_KNOWN_HOSTS_WITH_HOSTFILE"
"unset -v BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE"
if hostfile
else "COMP_KNOWN_HOSTS_WITH_HOSTFILE=",
else "BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE=",
)
output = assert_bash_exec(
bash,
Expand All @@ -66,11 +66,12 @@ def test_basic(
)
def test_ip_filtering(self, bash, family, result):
assert_bash_exec(
bash, "unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE"
bash,
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE",
)
output = assert_bash_exec(
bash,
"COMP_KNOWN_HOSTS_WITH_HOSTFILE= "
"BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE= "
"_known_hosts_real -%sF _known_hosts_real/localhost_config ''; "
r'printf "%%s\n" "${COMPREPLY[@]}"' % family,
want_output=True,
Expand All @@ -88,7 +89,7 @@ def test_consecutive_spaces(self, bash, hosts):

output = assert_bash_exec(
bash,
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE; "
"_known_hosts_real -aF '_known_hosts_real/spaced conf' ''; "
r'printf "%s\n" "${COMPREPLY[@]}"',
want_output=True,
Expand All @@ -108,8 +109,8 @@ def test_files_starting_with_tilde(self, bash, hosts):
bash_env.write_variable("HOME", bash.cwd)
output = assert_bash_exec(
bash,
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
"_known_hosts_real -aF _known_hosts_real/config_tilde ''; "
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
" _known_hosts_real -aF _known_hosts_real/config_tilde ''; "
r'printf "%s\n" "${COMPREPLY[@]}"',
want_output=True,
)
Expand All @@ -131,8 +132,8 @@ def test_included_configs(self, bash, hosts):
bash_env.write_variable("HOME", "%s/_known_hosts_real" % bash.cwd)
output = assert_bash_exec(
bash,
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
"_known_hosts_real -aF _known_hosts_real/config_include ''; "
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
" _known_hosts_real -aF _known_hosts_real/config_include ''; "
r'printf "%s\n" "${COMPREPLY[@]}"',
want_output=True,
)
Expand All @@ -144,8 +145,8 @@ def test_no_globbing(self, bash):
bash_env.chdir("_known_hosts_real")
output = assert_bash_exec(
bash,
"unset -v COMPREPLY COMP_KNOWN_HOSTS_WITH_HOSTFILE; "
"_known_hosts_real -aF config ''; "
"unset -v COMPREPLY BASH_COMPLETION_KNOWN_HOSTS_WITH_HOSTFILE;"
" _known_hosts_real -aF config ''; "
r'printf "%s\n" "${COMPREPLY[@]}"',
want_output=True,
)
Expand Down
2 changes: 1 addition & 1 deletion test/t/unit/test_unit_xinetd_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_env_non_pollution(self, bash):
def test_basic(self, bash):
output = assert_bash_exec(
bash,
"foo() { local BASHCOMP_XINETDDIR=$PWD/shared/bin;unset -v COMPREPLY; "
"foo() { local _comp__test_xinetd_dir=$PWD/shared/bin; unset -v COMPREPLY; "
'_xinetd_services; printf "%s\\n" "${COMPREPLY[@]}"; }; foo; unset -f foo',
want_output=True,
)
Expand Down