-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_tfctx
More file actions
executable file
·62 lines (54 loc) · 1.39 KB
/
_tfctx
File metadata and controls
executable file
·62 lines (54 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#compdef tfctx
# Find the root directory containing .terraform (searching upward)
_tfctx_find_root() {
local dir="$PWD"
while [[ "$dir" != "/" ]]; do
if [[ -d "$dir/.terraform" ]]; then
echo "$dir"
return 0
fi
dir="${dir:h}" # Get parent directory
done
return 1
}
local tf_root="${TFCTX_ROOT_DIR:-$PWD}"
local root="${TFCTX_ROOT:-envs}"
# Try to find terraform root if not set
if [[ -z "$TFCTX_ROOT_DIR" ]]; then
if tf_root=$(_tfctx_find_root); then
# Found terraform root
else
# Use current directory
tf_root="$PWD"
fi
fi
local -a envs
local -a commands
# Get available environments
for env_dir in ${tf_root}/${root}/*(N/); do
if [[ -d "$env_dir" ]]; then
envs+=("${env_dir:t}")
fi
done
# Define commands
commands=('create' 'ls')
if (( CURRENT == 2 )); then
# Add environments first (preserving order)
if (( ${#envs[@]} > 0 )); then
local -a env_completions
for env in ${envs[@]}; do
env_completions+=("$env:Switch to $env environment")
done
_describe -V 'environments' env_completions
fi
# Add commands
local -a command_completions
command_completions=(
"create:Create a new environment"
"ls:List available environments"
)
_describe -V 'commands' command_completions
elif [[ $words[2] == "create" && CURRENT == 3 ]]; then
# After 'create', don't offer completions (user types new env name)
return 1
fi