From d1a299949005498332bed7f3ac97b14f710ef9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:04:19 +0200 Subject: [PATCH 01/15] feat(__load_completion): localize default `$IFS` In order to be able to wrap loading 3rd party completions in enable+reset posix mode. https://github.com/scop/bash-completion/discussions/904#discussioncomment-5397380 --- bash_completion | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bash_completion b/bash_completion index 46f0cf1cb24..d1c06c09ede 100644 --- a/bash_completion +++ b/bash_completion @@ -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 From 77f2c6b2c75d99c14410953ad358615e8f2d3348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:12:29 +0200 Subject: [PATCH 02/15] refactor: refer to underscore prefixed files as "fallback" They are not always necessarily deprecated, but can serve as fallbacks due to other reasons. --- .pre-commit-config.yaml | 6 +++--- bash_completion | 2 +- configure.ac | 4 ++-- doc/api-and-naming.md | 4 ++-- test/Makefile.am | 2 +- test/config/bashrc | 4 ++-- test/deprecated/Makefile.am | 7 ------- test/deprecated/completions/README.md | 8 -------- test/fallback/Makefile.am | 7 +++++++ test/{deprecated => fallback}/completions/Makefile.am | 0 test/fallback/completions/README.md | 8 ++++++++ test/{deprecated => fallback}/completions/adb | 0 test/{deprecated => fallback}/completions/cal | 0 test/{deprecated => fallback}/completions/chfn | 0 test/{deprecated => fallback}/completions/chsh | 0 test/{deprecated => fallback}/completions/dmesg | 0 test/{deprecated => fallback}/completions/eject | 0 test/{deprecated => fallback}/completions/hexdump | 0 test/{deprecated => fallback}/completions/hwclock | 0 test/{deprecated => fallback}/completions/ionice | 0 test/{deprecated => fallback}/completions/look | 0 test/{deprecated => fallback}/completions/mock | 0 test/{deprecated => fallback}/completions/modules | 0 test/{deprecated => fallback}/completions/mount | 0 test/{deprecated => fallback}/completions/mount.linux | 0 test/{deprecated => fallback}/completions/newgrp | 0 test/{deprecated => fallback}/completions/nmcli | 0 test/{deprecated => fallback}/completions/op | 0 test/{deprecated => fallback}/completions/renice | 0 test/{deprecated => fallback}/completions/repomanage | 0 test/{deprecated => fallback}/completions/reptyr | 0 test/{deprecated => fallback}/completions/rfkill | 0 test/{deprecated => fallback}/completions/rtcwake | 0 test/{deprecated => fallback}/completions/runuser | 0 test/{deprecated => fallback}/completions/slackpkg | 0 test/{deprecated => fallback}/completions/su | 0 test/{deprecated => fallback}/completions/svn | 0 test/{deprecated => fallback}/completions/svnadmin | 0 test/{deprecated => fallback}/completions/svnlook | 0 test/{deprecated => fallback}/completions/udevadm | 0 test/{deprecated => fallback}/completions/umount | 0 test/{deprecated => fallback}/completions/umount.linux | 0 test/{deprecated => fallback}/completions/write | 0 test/{deprecated => fallback}/completions/xm | 0 test/{deprecated => fallback}/completions/yum | 0 .../update-fallback-links} | 0 46 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 test/deprecated/Makefile.am delete mode 100644 test/deprecated/completions/README.md create mode 100644 test/fallback/Makefile.am rename test/{deprecated => fallback}/completions/Makefile.am (100%) create mode 100644 test/fallback/completions/README.md rename test/{deprecated => fallback}/completions/adb (100%) rename test/{deprecated => fallback}/completions/cal (100%) rename test/{deprecated => fallback}/completions/chfn (100%) rename test/{deprecated => fallback}/completions/chsh (100%) rename test/{deprecated => fallback}/completions/dmesg (100%) rename test/{deprecated => fallback}/completions/eject (100%) rename test/{deprecated => fallback}/completions/hexdump (100%) rename test/{deprecated => fallback}/completions/hwclock (100%) rename test/{deprecated => fallback}/completions/ionice (100%) rename test/{deprecated => fallback}/completions/look (100%) rename test/{deprecated => fallback}/completions/mock (100%) rename test/{deprecated => fallback}/completions/modules (100%) rename test/{deprecated => fallback}/completions/mount (100%) rename test/{deprecated => fallback}/completions/mount.linux (100%) rename test/{deprecated => fallback}/completions/newgrp (100%) rename test/{deprecated => fallback}/completions/nmcli (100%) rename test/{deprecated => fallback}/completions/op (100%) rename test/{deprecated => fallback}/completions/renice (100%) rename test/{deprecated => fallback}/completions/repomanage (100%) rename test/{deprecated => fallback}/completions/reptyr (100%) rename test/{deprecated => fallback}/completions/rfkill (100%) rename test/{deprecated => fallback}/completions/rtcwake (100%) rename test/{deprecated => fallback}/completions/runuser (100%) rename test/{deprecated => fallback}/completions/slackpkg (100%) rename test/{deprecated => fallback}/completions/su (100%) rename test/{deprecated => fallback}/completions/svn (100%) rename test/{deprecated => fallback}/completions/svnadmin (100%) rename test/{deprecated => fallback}/completions/svnlook (100%) rename test/{deprecated => fallback}/completions/udevadm (100%) rename test/{deprecated => fallback}/completions/umount (100%) rename test/{deprecated => fallback}/completions/umount.linux (100%) rename test/{deprecated => fallback}/completions/write (100%) rename test/{deprecated => fallback}/completions/xm (100%) rename test/{deprecated => fallback}/completions/yum (100%) rename test/{deprecated/update-deprecated-links => fallback/update-fallback-links} (100%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e890f221a0b..1026e256296 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/bash_completion b/bash_completion index d1c06c09ede..77ff22087d1 100644 --- a/bash_completion +++ b/bash_completion @@ -2557,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" diff --git a/configure.ac b/configure.ac index 633e9dc0aa6..faab8df0de7 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]) diff --git a/doc/api-and-naming.md b/doc/api-and-naming.md index 8e25970ef4c..df5682b7aab 100644 --- a/doc/api-and-naming.md +++ b/doc/api-and-naming.md @@ -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. diff --git a/test/Makefile.am b/test/Makefile.am index 815c8095316..aaf32e02065 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = deprecated t +SUBDIRS = fallback t EXTRA_DIST = config \ fixtures \ diff --git a/test/config/bashrc b/test/config/bashrc index b6296f7c873..3a2d6df11fa 100644 --- a/test/config/bashrc +++ b/test/config/bashrc @@ -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 diff --git a/test/deprecated/Makefile.am b/test/deprecated/Makefile.am deleted file mode 100644 index e157948673c..00000000000 --- a/test/deprecated/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -SUBDIRS = completions - -EXTRA_DIST = \ - update-deprecated-links - -update: - ./update-deprecated-links diff --git a/test/deprecated/completions/README.md b/test/deprecated/completions/README.md deleted file mode 100644 index b4184d4a6a1..00000000000 --- a/test/deprecated/completions/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# test/deprecated/completions - -This directory should contain a non-underscore prefixed symlink to -corresponding underscore prefixed, deprecated 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 deprecated in-tree -completions over possibly installed non-deprecated out-of-tree ones. diff --git a/test/fallback/Makefile.am b/test/fallback/Makefile.am new file mode 100644 index 00000000000..096a1968254 --- /dev/null +++ b/test/fallback/Makefile.am @@ -0,0 +1,7 @@ +SUBDIRS = completions + +EXTRA_DIST = \ + update-fallback-links + +update: + ./update-fallback-links diff --git a/test/deprecated/completions/Makefile.am b/test/fallback/completions/Makefile.am similarity index 100% rename from test/deprecated/completions/Makefile.am rename to test/fallback/completions/Makefile.am diff --git a/test/fallback/completions/README.md b/test/fallback/completions/README.md new file mode 100644 index 00000000000..020e4b25080 --- /dev/null +++ b/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. diff --git a/test/deprecated/completions/adb b/test/fallback/completions/adb similarity index 100% rename from test/deprecated/completions/adb rename to test/fallback/completions/adb diff --git a/test/deprecated/completions/cal b/test/fallback/completions/cal similarity index 100% rename from test/deprecated/completions/cal rename to test/fallback/completions/cal diff --git a/test/deprecated/completions/chfn b/test/fallback/completions/chfn similarity index 100% rename from test/deprecated/completions/chfn rename to test/fallback/completions/chfn diff --git a/test/deprecated/completions/chsh b/test/fallback/completions/chsh similarity index 100% rename from test/deprecated/completions/chsh rename to test/fallback/completions/chsh diff --git a/test/deprecated/completions/dmesg b/test/fallback/completions/dmesg similarity index 100% rename from test/deprecated/completions/dmesg rename to test/fallback/completions/dmesg diff --git a/test/deprecated/completions/eject b/test/fallback/completions/eject similarity index 100% rename from test/deprecated/completions/eject rename to test/fallback/completions/eject diff --git a/test/deprecated/completions/hexdump b/test/fallback/completions/hexdump similarity index 100% rename from test/deprecated/completions/hexdump rename to test/fallback/completions/hexdump diff --git a/test/deprecated/completions/hwclock b/test/fallback/completions/hwclock similarity index 100% rename from test/deprecated/completions/hwclock rename to test/fallback/completions/hwclock diff --git a/test/deprecated/completions/ionice b/test/fallback/completions/ionice similarity index 100% rename from test/deprecated/completions/ionice rename to test/fallback/completions/ionice diff --git a/test/deprecated/completions/look b/test/fallback/completions/look similarity index 100% rename from test/deprecated/completions/look rename to test/fallback/completions/look diff --git a/test/deprecated/completions/mock b/test/fallback/completions/mock similarity index 100% rename from test/deprecated/completions/mock rename to test/fallback/completions/mock diff --git a/test/deprecated/completions/modules b/test/fallback/completions/modules similarity index 100% rename from test/deprecated/completions/modules rename to test/fallback/completions/modules diff --git a/test/deprecated/completions/mount b/test/fallback/completions/mount similarity index 100% rename from test/deprecated/completions/mount rename to test/fallback/completions/mount diff --git a/test/deprecated/completions/mount.linux b/test/fallback/completions/mount.linux similarity index 100% rename from test/deprecated/completions/mount.linux rename to test/fallback/completions/mount.linux diff --git a/test/deprecated/completions/newgrp b/test/fallback/completions/newgrp similarity index 100% rename from test/deprecated/completions/newgrp rename to test/fallback/completions/newgrp diff --git a/test/deprecated/completions/nmcli b/test/fallback/completions/nmcli similarity index 100% rename from test/deprecated/completions/nmcli rename to test/fallback/completions/nmcli diff --git a/test/deprecated/completions/op b/test/fallback/completions/op similarity index 100% rename from test/deprecated/completions/op rename to test/fallback/completions/op diff --git a/test/deprecated/completions/renice b/test/fallback/completions/renice similarity index 100% rename from test/deprecated/completions/renice rename to test/fallback/completions/renice diff --git a/test/deprecated/completions/repomanage b/test/fallback/completions/repomanage similarity index 100% rename from test/deprecated/completions/repomanage rename to test/fallback/completions/repomanage diff --git a/test/deprecated/completions/reptyr b/test/fallback/completions/reptyr similarity index 100% rename from test/deprecated/completions/reptyr rename to test/fallback/completions/reptyr diff --git a/test/deprecated/completions/rfkill b/test/fallback/completions/rfkill similarity index 100% rename from test/deprecated/completions/rfkill rename to test/fallback/completions/rfkill diff --git a/test/deprecated/completions/rtcwake b/test/fallback/completions/rtcwake similarity index 100% rename from test/deprecated/completions/rtcwake rename to test/fallback/completions/rtcwake diff --git a/test/deprecated/completions/runuser b/test/fallback/completions/runuser similarity index 100% rename from test/deprecated/completions/runuser rename to test/fallback/completions/runuser diff --git a/test/deprecated/completions/slackpkg b/test/fallback/completions/slackpkg similarity index 100% rename from test/deprecated/completions/slackpkg rename to test/fallback/completions/slackpkg diff --git a/test/deprecated/completions/su b/test/fallback/completions/su similarity index 100% rename from test/deprecated/completions/su rename to test/fallback/completions/su diff --git a/test/deprecated/completions/svn b/test/fallback/completions/svn similarity index 100% rename from test/deprecated/completions/svn rename to test/fallback/completions/svn diff --git a/test/deprecated/completions/svnadmin b/test/fallback/completions/svnadmin similarity index 100% rename from test/deprecated/completions/svnadmin rename to test/fallback/completions/svnadmin diff --git a/test/deprecated/completions/svnlook b/test/fallback/completions/svnlook similarity index 100% rename from test/deprecated/completions/svnlook rename to test/fallback/completions/svnlook diff --git a/test/deprecated/completions/udevadm b/test/fallback/completions/udevadm similarity index 100% rename from test/deprecated/completions/udevadm rename to test/fallback/completions/udevadm diff --git a/test/deprecated/completions/umount b/test/fallback/completions/umount similarity index 100% rename from test/deprecated/completions/umount rename to test/fallback/completions/umount diff --git a/test/deprecated/completions/umount.linux b/test/fallback/completions/umount.linux similarity index 100% rename from test/deprecated/completions/umount.linux rename to test/fallback/completions/umount.linux diff --git a/test/deprecated/completions/write b/test/fallback/completions/write similarity index 100% rename from test/deprecated/completions/write rename to test/fallback/completions/write diff --git a/test/deprecated/completions/xm b/test/fallback/completions/xm similarity index 100% rename from test/deprecated/completions/xm rename to test/fallback/completions/xm diff --git a/test/deprecated/completions/yum b/test/fallback/completions/yum similarity index 100% rename from test/deprecated/completions/yum rename to test/fallback/completions/yum diff --git a/test/deprecated/update-deprecated-links b/test/fallback/update-fallback-links similarity index 100% rename from test/deprecated/update-deprecated-links rename to test/fallback/update-fallback-links From f402bf005abdd9f7ff2a63f5ef9130d750246753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:25:44 +0200 Subject: [PATCH 03/15] feat(gh): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_gh | 18 ++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/gh | 1 + 4 files changed, 21 insertions(+) create mode 100644 completions/_gh create mode 120000 test/fallback/completions/gh diff --git a/completions/Makefile.am b/completions/Makefile.am index 1712dd193f0..690009e1c96 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -130,6 +130,7 @@ bashcomp_DATA = 2to3 \ geoiplookup \ getconf \ getent \ + _gh \ gkrellm \ gm \ gnatmake \ diff --git a/completions/_gh b/completions/_gh new file mode 100644 index 00000000000..91d09bb739d --- /dev/null +++ b/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) + +$_comp__load_3rdparty_reset_shopt + +{ + complete -p "$1" || complete -p "${1##*/}" +} &>/dev/null + +# ex: filetype=sh diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 2c65094ab0e..990bcd77178 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -5,6 +5,7 @@ EXTRA_DIST = \ chsh \ dmesg \ eject \ + gh \ hexdump \ hwclock \ ionice \ diff --git a/test/fallback/completions/gh b/test/fallback/completions/gh new file mode 120000 index 00000000000..823628f588d --- /dev/null +++ b/test/fallback/completions/gh @@ -0,0 +1 @@ +../../../completions/_gh \ No newline at end of file From 363b9fce79b73b639b5bfce8fe241b04868d8176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:35:38 +0200 Subject: [PATCH 04/15] feat(golangci-lint): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_golangci-lint | 19 +++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/golangci-lint | 1 + 4 files changed, 22 insertions(+) create mode 100644 completions/_golangci-lint create mode 120000 test/fallback/completions/golangci-lint diff --git a/completions/Makefile.am b/completions/Makefile.am index 690009e1c96..f55797819ed 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -137,6 +137,7 @@ bashcomp_DATA = 2to3 \ gnokii \ gnome-mplayer \ gnome-screenshot \ + _golangci-lint \ gpasswd \ gpg \ gpg2 \ diff --git a/completions/_golangci-lint b/completions/_golangci-lint new file mode 100644 index 00000000000..0ed43f680e7 --- /dev/null +++ b/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 diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 990bcd77178..2d371a3875f 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -6,6 +6,7 @@ EXTRA_DIST = \ dmesg \ eject \ gh \ + golangci-lint \ hexdump \ hwclock \ ionice \ diff --git a/test/fallback/completions/golangci-lint b/test/fallback/completions/golangci-lint new file mode 120000 index 00000000000..b0fa4ef1c08 --- /dev/null +++ b/test/fallback/completions/golangci-lint @@ -0,0 +1 @@ +../../../completions/_golangci-lint \ No newline at end of file From 031e317c6688f2129995bc44851bb7a9d689a33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:43:21 +0200 Subject: [PATCH 05/15] feat(hugo): add fallback 3rd party completion loader --- completions/.gitignore | 1 + completions/Makefile.am | 3 +++ 2 files changed, 4 insertions(+) diff --git a/completions/.gitignore b/completions/.gitignore index 0dd1db1e8d0..56c48faeab9 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -84,6 +84,7 @@ /host /hping /hping3 +/_hugo /iceweasel /identify /ifdown diff --git a/completions/Makefile.am b/completions/Makefile.am index f55797819ed..b03243fe864 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -595,6 +595,7 @@ CLEANFILES = \ host \ hping \ hping3 \ + _hugo \ iceweasel \ identify \ ifdown \ @@ -868,6 +869,8 @@ symlinks: $(DATA) geoiplookup6 $(ss) gkrellm \ gkrellm2 + $(ss) _golangci-lint \ + _hugo $(ss) gpgv \ gpgv2 $(ss) gssdp-discover \ From f4e310952c3c5c4e2d140e8019713c614b1b6ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:47:26 +0200 Subject: [PATCH 06/15] feat(upctl): add fallback 3rd party completion loader --- completions/.gitignore | 1 + completions/Makefile.am | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/.gitignore b/completions/.gitignore index 56c48faeab9..a1ac3a433c5 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -230,6 +230,7 @@ /tightvncviewer /tracepath6 /typeset +/_upctl /vgcfgbackup /vgcfgrestore /vgchange diff --git a/completions/Makefile.am b/completions/Makefile.am index b03243fe864..442e811f05a 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -773,6 +773,7 @@ CLEANFILES = \ tightvncviewer \ tracepath6 \ typeset \ + _upctl \ vgcfgbackup \ vgcfgrestore \ vgchange \ @@ -870,7 +871,7 @@ symlinks: $(DATA) $(ss) gkrellm \ gkrellm2 $(ss) _golangci-lint \ - _hugo + _hugo _upctl $(ss) gpgv \ gpgv2 $(ss) gssdp-discover \ From ef651f82051951e1a5782d48ef453d0957fa9410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:49:41 +0200 Subject: [PATCH 07/15] feat(sshi): add fallback 3rd party completion loader --- completions/.gitignore | 1 + completions/Makefile.am | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/.gitignore b/completions/.gitignore index a1ac3a433c5..557102deba1 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -224,6 +224,7 @@ /smbtree /sparc-koji /spovray +/_sshi /star /stream /sudoedit diff --git a/completions/Makefile.am b/completions/Makefile.am index 442e811f05a..587e90bca52 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -767,6 +767,7 @@ CLEANFILES = \ smbtree \ sparc-koji \ spovray \ + _sshi \ star \ stream \ sudoedit \ @@ -871,7 +872,7 @@ symlinks: $(DATA) $(ss) gkrellm \ gkrellm2 $(ss) _golangci-lint \ - _hugo _upctl + _hugo _sshi _upctl $(ss) gpgv \ gpgv2 $(ss) gssdp-discover \ From 3a1103e26ccffb96befd272b7d39c01923c42f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:50:27 +0200 Subject: [PATCH 08/15] feat(vacuum): add fallback 3rd party completion loader --- completions/.gitignore | 1 + completions/Makefile.am | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/.gitignore b/completions/.gitignore index 557102deba1..b5e9cd5c1d0 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -232,6 +232,7 @@ /tracepath6 /typeset /_upctl +/_vacuum /vgcfgbackup /vgcfgrestore /vgchange diff --git a/completions/Makefile.am b/completions/Makefile.am index 587e90bca52..bb78ef79094 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -775,6 +775,7 @@ CLEANFILES = \ tracepath6 \ typeset \ _upctl \ + _vacuum \ vgcfgbackup \ vgcfgrestore \ vgchange \ @@ -872,7 +873,7 @@ symlinks: $(DATA) $(ss) gkrellm \ gkrellm2 $(ss) _golangci-lint \ - _hugo _sshi _upctl + _hugo _sshi _upctl _vacuum $(ss) gpgv \ gpgv2 $(ss) gssdp-discover \ From 3c1947bc3bcb0cead57c522028ecb161e6ce43d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:52:38 +0200 Subject: [PATCH 09/15] feat(yq): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_yq | 18 ++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/yq | 1 + 4 files changed, 21 insertions(+) create mode 100644 completions/_yq create mode 120000 test/fallback/completions/yq diff --git a/completions/Makefile.am b/completions/Makefile.am index bb78ef79094..013d2f39dc6 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -477,6 +477,7 @@ bashcomp_DATA = 2to3 \ xz \ xzdec \ ypmatch \ + _yq \ _yum \ yum-arch \ zopfli \ diff --git a/completions/_yq b/completions/_yq new file mode 100644 index 00000000000..e0a93368bce --- /dev/null +++ b/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 diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 2d371a3875f..5f36bf0bf5b 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -34,4 +34,5 @@ EXTRA_DIST = \ umount.linux \ write \ xm \ + yq \ yum diff --git a/test/fallback/completions/yq b/test/fallback/completions/yq new file mode 120000 index 00000000000..9ea0a280db2 --- /dev/null +++ b/test/fallback/completions/yq @@ -0,0 +1 @@ +../../../completions/_yq \ No newline at end of file From d27b144016439f6b5e9fcebca6779ca61a23b9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 12:58:01 +0200 Subject: [PATCH 10/15] feat(ruff): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_ruff | 18 ++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/ruff | 1 + 4 files changed, 21 insertions(+) create mode 100644 completions/_ruff create mode 120000 test/fallback/completions/ruff diff --git a/completions/Makefile.am b/completions/Makefile.am index 013d2f39dc6..9d678559eb3 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -375,6 +375,7 @@ bashcomp_DATA = 2to3 \ rrdtool \ rsync \ _rtcwake \ + _ruff \ _runuser \ sbcl \ sbopkg \ diff --git a/completions/_ruff b/completions/_ruff new file mode 100644 index 00000000000..81240d7e29f --- /dev/null +++ b/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 diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 5f36bf0bf5b..0f2bc20191f 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST = \ reptyr \ rfkill \ rtcwake \ + ruff \ runuser \ slackpkg \ su \ diff --git a/test/fallback/completions/ruff b/test/fallback/completions/ruff new file mode 120000 index 00000000000..2d6104b324f --- /dev/null +++ b/test/fallback/completions/ruff @@ -0,0 +1 @@ +../../../completions/_ruff \ No newline at end of file From 8610d7dc8b9b3630b469a3982a162e218bf967ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 13:01:40 +0200 Subject: [PATCH 11/15] feat(rustup): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_rustup | 17 +++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/rustup | 1 + 4 files changed, 20 insertions(+) create mode 100644 completions/_rustup create mode 120000 test/fallback/completions/rustup diff --git a/completions/Makefile.am b/completions/Makefile.am index 9d678559eb3..09c18d223c9 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -377,6 +377,7 @@ bashcomp_DATA = 2to3 \ _rtcwake \ _ruff \ _runuser \ + _rustup \ sbcl \ sbopkg \ screen \ diff --git a/completions/_rustup b/completions/_rustup new file mode 100644 index 00000000000..6d3cdfda0e0 --- /dev/null +++ b/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 diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 0f2bc20191f..a3930394290 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -25,6 +25,7 @@ EXTRA_DIST = \ rtcwake \ ruff \ runuser \ + rustup \ slackpkg \ su \ svn \ diff --git a/test/fallback/completions/rustup b/test/fallback/completions/rustup new file mode 120000 index 00000000000..18b256a7dfd --- /dev/null +++ b/test/fallback/completions/rustup @@ -0,0 +1 @@ +../../../completions/_rustup \ No newline at end of file From 7cd9cb91408cebbd112bf3643184647006fe2490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 13:05:14 +0200 Subject: [PATCH 12/15] feat(cargo): add fallback 3rd party completion loader --- completions/Makefile.am | 1 + completions/_cargo | 18 ++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/cargo | 1 + 4 files changed, 21 insertions(+) create mode 100644 completions/_cargo create mode 120000 test/fallback/completions/cargo diff --git a/completions/Makefile.am b/completions/Makefile.am index 09c18d223c9..3f402167807 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -38,6 +38,7 @@ bashcomp_DATA = 2to3 \ bzip2 \ _cal \ cancel \ + _cargo \ cardctl \ carton \ ccache \ diff --git a/completions/_cargo b/completions/_cargo new file mode 100644 index 00000000000..10b662a4846 --- /dev/null +++ b/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 diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index a3930394290..9c4194cb424 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -1,6 +1,7 @@ EXTRA_DIST = \ adb \ cal \ + cargo \ chfn \ chsh \ dmesg \ diff --git a/test/fallback/completions/cargo b/test/fallback/completions/cargo new file mode 120000 index 00000000000..cdc7c30243d --- /dev/null +++ b/test/fallback/completions/cargo @@ -0,0 +1 @@ +../../../completions/_cargo \ No newline at end of file From 56186541f5a382056cfc25e1d08f5da8018076b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 13:31:50 +0200 Subject: [PATCH 13/15] feat(__load_completion): pass backslashless command to fallback loads So that things work also for commands preceded by a backslash. Co-authored-by: Koichi Murase --- bash_completion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index 77ff22087d1..084465b4227 100644 --- a/bash_completion +++ b/bash_completion @@ -2567,7 +2567,7 @@ __load_completion() # Do not warn with . or .. (especially the former is common) [[ $compfile == */.?(.) ]] || echo "bash_completion: $compfile: is a directory" >&2 - elif [[ -e $compfile ]] && . "$compfile"; then + elif [[ -e $compfile ]] && . "$compfile" "$cmd"; then [[ $backslash ]] && $(complete -p "$cmd") "\\$cmd" return 0 fi From 328ecf74bc5cb14c91329d8fb1922b9d033ade1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 23 Mar 2023 14:04:54 +0200 Subject: [PATCH 14/15] feat(kn): add fallback 3rd party completion loader --- completions/.gitignore | 1 + completions/Makefile.am | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/completions/.gitignore b/completions/.gitignore index b5e9cd5c1d0..1eb41747b3b 100644 --- a/completions/.gitignore +++ b/completions/.gitignore @@ -96,6 +96,7 @@ /iperf3 /javac /javadoc +/_kn /kplayer /l2ping /lbzip2 diff --git a/completions/Makefile.am b/completions/Makefile.am index 3f402167807..352be8483d6 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -611,6 +611,7 @@ CLEANFILES = \ iperf3 \ javac \ javadoc \ + _kn \ kplayer \ l2ping \ lbzip2 \ @@ -877,7 +878,7 @@ symlinks: $(DATA) $(ss) gkrellm \ gkrellm2 $(ss) _golangci-lint \ - _hugo _sshi _upctl _vacuum + _hugo _kn _sshi _upctl _vacuum $(ss) gpgv \ gpgv2 $(ss) gssdp-discover \ From 43da208ace65a924262838aa977e9b22fcd780fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 26 Mar 2023 14:30:51 +0300 Subject: [PATCH 15/15] refactor: use `eval` instead of tweaking POSIX mode in 3rd party loaders Per the note in CONTRIBUTING.md, https://github.com/scop/bash-completion/pull/905#discussion_r1146950905 --- completions/_cargo | 7 +------ completions/_gh | 8 +------- completions/_golangci-lint | 8 +------- completions/_ruff | 8 +------- completions/_rustup | 8 +------- completions/_yq | 8 +------- 6 files changed, 6 insertions(+), 41 deletions(-) diff --git a/completions/_cargo b/completions/_cargo index 10b662a4846..fcb5e2781df 100644 --- a/completions/_cargo +++ b/completions/_cargo @@ -3,13 +3,8 @@ # 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 +eval -- "$("$rustup" completions bash cargo 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}" diff --git a/completions/_gh b/completions/_gh index 91d09bb739d..7b0daefed8b 100644 --- a/completions/_gh +++ b/completions/_gh @@ -3,13 +3,7 @@ # # 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) - -$_comp__load_3rdparty_reset_shopt +eval -- "$("$1" completion --shell bash 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}" diff --git a/completions/_golangci-lint b/completions/_golangci-lint index 0ed43f680e7..830fa536aa0 100644 --- a/completions/_golangci-lint +++ b/completions/_golangci-lint @@ -4,13 +4,7 @@ # # 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 +eval -- "$("$1" completion bash 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}" diff --git a/completions/_ruff b/completions/_ruff index 81240d7e29f..71f7c0c6524 100644 --- a/completions/_ruff +++ b/completions/_ruff @@ -3,13 +3,7 @@ # # 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 +eval -- "$("$1" generate-shell-completion bash 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}" diff --git a/completions/_rustup b/completions/_rustup index 6d3cdfda0e0..0f2fe6e4056 100644 --- a/completions/_rustup +++ b/completions/_rustup @@ -2,13 +2,7 @@ # # 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 +eval -- "$("$1" completions bash rustup 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}" diff --git a/completions/_yq b/completions/_yq index e0a93368bce..ff662bf9ede 100644 --- a/completions/_yq +++ b/completions/_yq @@ -3,13 +3,7 @@ # # 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 +eval -- "$("$1" shell-completion bash 2>/dev/null)" { complete -p "$1" || complete -p "${1##*/}"