Skip to content

Commit 1cb987f

Browse files
committed
Tofu completion rewrite
1 parent 285ea44 commit 1cb987f

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# shellcheck shell=bash
2+
about-completion "terraform/tofu completion"
23

3-
if _command_exists terraform; then
4-
5-
# Don't handle completion if it's already managed
6-
complete -p terraform &> /dev/null && return
7-
8-
# Terraform completes itself
9-
complete -C terraform terraform
10-
11-
elif _command_exists tofu; then
12-
13-
# Don't handle completion if it's already managed
14-
complete -p tofu &> /dev/null && return
15-
16-
# OpenTofu completes itself
17-
complete -C tofu tofu
4+
# Note, this is not using the _bash-it-completion-helper-necessary function
5+
# because it's a multiple choice case, and will therefore produce more
6+
# sensible log messages.
187

8+
# Check if at least one of the binaries is available (OR logic)
9+
if ! _binary_exists terraform && ! _binary_exists tofu; then
10+
_log_warning "Without 'terraform' or 'tofu' installed, this completion won't be too useful."
11+
return 1
1912
fi
2013

14+
# Handle terraform completion if available and not already managed
15+
if _binary_exists terraform; then
16+
_bash-it-completion-helper-sufficient terraform || {
17+
# Terraform completes itself
18+
complete -C terraform terraform
19+
}
20+
fi
2121

22-
23-
## TODO: change the logic to the new way of doing things?
24-
## Make sure terraform is installed
25-
#_bash-it-completion-helper-necessary terraform || return
26-
27-
## Don't handle completion if it's already managed
28-
#_bash-it-completion-helper-sufficient terraform || return
22+
# Handle tofu completion if available and not already managed
23+
if _binary_exists tofu; then
24+
_bash-it-completion-helper-sufficient tofu || {
25+
# OpenTofu completes itself
26+
complete -C tofu tofu
27+
}
28+
fi

0 commit comments

Comments
 (0)