Skip to content
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

feat: add 3rd party generated completion fallbacks #905

Merged
merged 15 commits into from Mar 26, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Expand Up @@ -34,10 +34,10 @@ repos:
files: ^test/t/.+\.py$
pass_filenames: false

- id: update-test-deprecated-links
name: update-test-deprecated-links
- id: update-test-fallback-links
name: update-test-fallback-links
language: script
entry: test/deprecated/update-deprecated-links
entry: test/fallback/update-fallback-links
files: ^completions/_
pass_filenames: false

Expand Down
5 changes: 4 additions & 1 deletion bash_completion
Expand Up @@ -2537,6 +2537,9 @@ __load_completion()
backslash=\\
fi

# For loading 3rd party completions wrapped in shopt reset
local IFS=$' \t\n'

for dir in "${dirs[@]}"; do
[[ -d $dir ]] || continue
for compfile in "$cmd" "$cmd.bash"; do
Expand All @@ -2554,7 +2557,7 @@ __load_completion()
done
done

# search deprecated completions "_$cmd"
# Search fallback completions named "_$cmd"
for dir in "${dirs[@]}"; do
[[ -d $dir ]] || continue
compfile="$dir/_$cmd"
Expand Down
4 changes: 4 additions & 0 deletions completions/.gitignore
Expand Up @@ -84,6 +84,7 @@
/host
/hping
/hping3
/_hugo
/iceweasel
/identify
/ifdown
Expand Down Expand Up @@ -223,12 +224,15 @@
/smbtree
/sparc-koji
/spovray
/_sshi
/star
/stream
/sudoedit
/tightvncviewer
/tracepath6
/typeset
/_upctl
/_vacuum
/vgcfgbackup
/vgcfgrestore
/vgchange
Expand Down
12 changes: 12 additions & 0 deletions completions/Makefile.am
Expand Up @@ -38,6 +38,7 @@ bashcomp_DATA = 2to3 \
bzip2 \
_cal \
cancel \
_cargo \
cardctl \
carton \
ccache \
Expand Down Expand Up @@ -130,12 +131,14 @@ bashcomp_DATA = 2to3 \
geoiplookup \
getconf \
getent \
_gh \
gkrellm \
gm \
gnatmake \
gnokii \
gnome-mplayer \
gnome-screenshot \
_golangci-lint \
gpasswd \
gpg \
gpg2 \
Expand Down Expand Up @@ -373,7 +376,9 @@ bashcomp_DATA = 2to3 \
rrdtool \
rsync \
_rtcwake \
_ruff \
_runuser \
_rustup \
sbcl \
sbopkg \
screen \
Expand Down Expand Up @@ -475,6 +480,7 @@ bashcomp_DATA = 2to3 \
xz \
xzdec \
ypmatch \
_yq \
_yum \
yum-arch \
zopfli \
Expand Down Expand Up @@ -593,6 +599,7 @@ CLEANFILES = \
host \
hping \
hping3 \
_hugo \
iceweasel \
identify \
ifdown \
Expand Down Expand Up @@ -764,12 +771,15 @@ CLEANFILES = \
smbtree \
sparc-koji \
spovray \
_sshi \
star \
stream \
sudoedit \
tightvncviewer \
tracepath6 \
typeset \
_upctl \
_vacuum \
vgcfgbackup \
vgcfgrestore \
vgchange \
Expand Down Expand Up @@ -866,6 +876,8 @@ symlinks: $(DATA)
geoiplookup6
$(ss) gkrellm \
gkrellm2
$(ss) _golangci-lint \
_hugo _sshi _upctl _vacuum
$(ss) gpgv \
gpgv2
$(ss) gssdp-discover \
Expand Down
18 changes: 18 additions & 0 deletions completions/_cargo
@@ -0,0 +1,18 @@
# 3rd party completion loader for cargo -*- shell-script -*-
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

local rustup="${1%cargo}rustup" # use rustup from same dir
. <("$rustup" completions bash cargo 2>/dev/null)

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
18 changes: 18 additions & 0 deletions completions/_gh
@@ -0,0 +1,18 @@
# 3rd party completion loader for commands emitting -*- shell-script -*-
# their completion using "$cmd completion --shell bash".
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

. <("$1" completion --shell bash 2>/dev/null)
akinomyoga marked this conversation as resolved.
Show resolved Hide resolved

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
19 changes: 19 additions & 0 deletions completions/_golangci-lint
@@ -0,0 +1,19 @@
# 3rd party completion loader for commands emitting -*- shell-script -*-
# their completion using "$cmd completion bash".
# For example, many Go programs using https://github.com/spf13/cobra do.
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

. <("$1" completion bash 2>/dev/null)

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
18 changes: 18 additions & 0 deletions completions/_ruff
@@ -0,0 +1,18 @@
# 3rd party completion loader for commands emitting -*- shell-script -*-
# their completion using "$cmd generate-shell-completion bash".
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

. <("$1" generate-shell-completion bash 2>/dev/null)

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
17 changes: 17 additions & 0 deletions completions/_rustup
@@ -0,0 +1,17 @@
# 3rd party completion loader for rustup -*- shell-script -*-
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

. <("$1" completions bash rustup 2>/dev/null)

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
18 changes: 18 additions & 0 deletions completions/_yq
@@ -0,0 +1,18 @@
# 3rd party completion loader for commands emitting -*- shell-script -*-
# their completion using "$cmd shell-completion bash".
#
# This serves as a fallback in case the completion is not installed otherwise.

# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
set +o posix

. <("$1" shell-completion bash 2>/dev/null)

$_comp__load_3rdparty_reset_shopt

{
complete -p "$1" || complete -p "${1##*/}"
} &>/dev/null

# ex: filetype=sh
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -17,8 +17,8 @@ completions/Makefile
doc/Makefile
helpers/Makefile
test/Makefile
test/deprecated/Makefile
test/deprecated/completions/Makefile
test/fallback/Makefile
test/fallback/completions/Makefile
test/t/Makefile
test/t/unit/Makefile
])
Expand Down
4 changes: 2 additions & 2 deletions doc/api-and-naming.md
Expand Up @@ -19,8 +19,8 @@ each call that references the value, variable name, or their existence,
typically by `unset -v`ing them when multiple such calls are used,
to avoid them interfering with each other.

Everything in deprecated completion files (ones starting with an underscore)
is considered private and is to be named accordingly. Deprecated files are not
Everything in fallback completion files (ones starting with an underscore)
is considered private and is to be named accordingly. Fallback files are not
intended to be explicitly used with `_comp_xfunc`, and completion files having
precedence over them may have a different API.

Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am
@@ -1,4 +1,4 @@
SUBDIRS = deprecated t
SUBDIRS = fallback t

EXTRA_DIST = config \
fixtures \
Expand Down
4 changes: 2 additions & 2 deletions test/config/bashrc
Expand Up @@ -34,9 +34,9 @@ export BASH_COMPLETION_USER_FILE=/dev/null
# overriding in-tree completions. Setting the user dir would otherwise suffice,
# but simple xspec completions are only installed if a separate one is not
# found in *any* completion dirs, and we want to use our "shadow" completion
# dir with which we cause loading of our in-tree deprecated completions
# dir with which we cause loading of our in-tree fallback completions
# instead of possibly (system-)installed upstream ones.
export BASH_COMPLETION_USER_DIR="$SRCDIRABS/deprecated"
export BASH_COMPLETION_USER_DIR="$SRCDIRABS/fallback"
export BASH_COMPLETION_COMPAT_DIR="$SRCDIRABS/../bash_completion.d"
export XDG_DATA_DIRS=/var/empty

Expand Down
7 changes: 0 additions & 7 deletions test/deprecated/Makefile.am

This file was deleted.

8 changes: 0 additions & 8 deletions test/deprecated/completions/README.md

This file was deleted.

7 changes: 7 additions & 0 deletions test/fallback/Makefile.am
@@ -0,0 +1,7 @@
SUBDIRS = completions

EXTRA_DIST = \
update-fallback-links

update:
./update-fallback-links
@@ -1,10 +1,13 @@
EXTRA_DIST = \
adb \
cal \
cargo \
chfn \
chsh \
dmesg \
eject \
gh \
golangci-lint \
hexdump \
hwclock \
ionice \
Expand All @@ -21,7 +24,9 @@ EXTRA_DIST = \
reptyr \
rfkill \
rtcwake \
ruff \
runuser \
rustup \
slackpkg \
su \
svn \
Expand All @@ -32,4 +37,5 @@ EXTRA_DIST = \
umount.linux \
write \
xm \
yq \
yum
8 changes: 8 additions & 0 deletions test/fallback/completions/README.md
@@ -0,0 +1,8 @@
# test/fallback/completions

This directory should contain a non-underscore prefixed symlink to
corresponding underscore prefixed, fallback completions we have in the tree.

The test suite sets up loading of completions so that this dir is preferred
over system install locations, in order to test our fallback in-tree
completions over possibly installed non-fallback out-of-tree ones.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fallback/completions/cargo
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fallback/completions/gh
1 change: 1 addition & 0 deletions test/fallback/completions/golangci-lint
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fallback/completions/ruff
File renamed without changes.
1 change: 1 addition & 0 deletions test/fallback/completions/rustup
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fallback/completions/yq
File renamed without changes.