Skip to content

Commit 7cd9cb9

Browse files
committed
feat(cargo): add fallback 3rd party completion loader
1 parent 8610d7d commit 7cd9cb9

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
@@ -38,6 +38,7 @@ bashcomp_DATA = 2to3 \
3838
bzip2 \
3939
_cal \
4040
cancel \
41+
_cargo \
4142
cardctl \
4243
carton \
4344
ccache \

completions/_cargo

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 3rd party completion loader for cargo -*- shell-script -*-
2+
#
3+
# This serves as a fallback in case the completion is not installed otherwise.
4+
5+
# shellcheck disable=SC2168 # "local" is ok, assume sourced by __load_completion
6+
local _comp__load_3rdparty_reset_shopt=$(shopt -po posix)
7+
set +o posix
8+
9+
local rustup="${1%cargo}rustup" # use rustup from same dir
10+
. <("$rustup" completions bash cargo 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
@@ -1,6 +1,7 @@
11
EXTRA_DIST = \
22
adb \
33
cal \
4+
cargo \
45
chfn \
56
chsh \
67
dmesg \

test/fallback/completions/cargo

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

0 commit comments

Comments
 (0)