Skip to content

Commit e2488f2

Browse files
authored
Merge pull request #2333 from Bash-it/ira/completion-cleanup
2 parents a56a7a2 + 1cb987f commit e2488f2

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
---
44
# fail_fast: true
55
minimum_pre_commit_version: 1.18.1
6-
exclude: "docs/_build/"
6+
exclude: "docs/_build/|vendor/"
77
repos:
88
- repo: https://github.com/pre-commit/pre-commit-hooks
99
rev: v2.3.0
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)