Skip to content

Commit 3c1947b

Browse files
committed
feat(yq): add fallback 3rd party completion loader
1 parent 3a1103e commit 3c1947b

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ bashcomp_DATA = 2to3 \
477477
xz \
478478
xzdec \
479479
ypmatch \
480+
_yq \
480481
_yum \
481482
yum-arch \
482483
zopfli \

completions/_yq

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 3rd party completion loader for commands emitting -*- shell-script -*-
2+
# their completion using "$cmd shell-completion bash".
3+
#
4+
# This serves as a fallback in case the completion is not installed otherwise.
5+
6+
# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
7+
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
8+
set +o posix
9+
10+
. <("$1" shell-completion bash 2>/dev/null)
11+
12+
$_comp__load_3rdparty_reset_shopt
13+
14+
{
15+
complete -p "$1" || complete -p "${1##*/}"
16+
} &>/dev/null
17+
18+
# ex: filetype=sh

test/fallback/completions/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ EXTRA_DIST = \
3434
umount.linux \
3535
write \
3636
xm \
37+
yq \
3738
yum

test/fallback/completions/yq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../completions/_yq

0 commit comments

Comments
 (0)