Skip to content

Commit f402bf0

Browse files
committed
feat(gh): add fallback 3rd party completion loader
1 parent 77f2c6b commit f402bf0

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
@@ -130,6 +130,7 @@ bashcomp_DATA = 2to3 \
130130
geoiplookup \
131131
getconf \
132132
getent \
133+
_gh \
133134
gkrellm \
134135
gm \
135136
gnatmake \

completions/_gh

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 completion --shell 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" completion --shell 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
@@ -5,6 +5,7 @@ EXTRA_DIST = \
55
chsh \
66
dmesg \
77
eject \
8+
gh \
89
hexdump \
910
hwclock \
1011
ionice \

test/fallback/completions/gh

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

0 commit comments

Comments
 (0)