-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletions.bash
More file actions
57 lines (50 loc) · 2.25 KB
/
completions.bash
File metadata and controls
57 lines (50 loc) · 2.25 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
__comp_cache="${XDG_CACHE_HOME:-$HOME/.cache}/bash/completions.cache"
# Source cache if available (instant)
[[ -f "$__comp_cache" ]] && source "$__comp_cache"
# Regenerate cache in background
(
_out=""
# Standard: <cmd> completion bash
for cmd in kubectl helm docker podman argocd oc harbor; do
command -v "$cmd" &>/dev/null && _out+="$("$cmd" completion bash 2>/dev/null)"$'\n'
done
# Special cases
command -v gh &>/dev/null && _out+="$(gh completion -s bash 2>/dev/null)"$'\n'
command -v npm &>/dev/null && _out+="$(npm completion 2>/dev/null)"$'\n'
command -v pip &>/dev/null && _out+="$(pip completion --bash 2>/dev/null)"$'\n'
command -v rustup &>/dev/null && _out+="$(rustup completions bash 2>/dev/null)"$'\n'
command -v cargo &>/dev/null && _out+="$(rustup completions bash cargo 2>/dev/null)"$'\n'
command -v uv &>/dev/null && _out+="$(uv generate-shell-completion bash 2>/dev/null)"$'\n'
command -v uvx &>/dev/null && _out+="$(uvx --generate-shell-completion bash 2>/dev/null)"$'\n'
command -v terraform &>/dev/null && _out+="complete -C terraform terraform"$'\n'
mkdir -p "$(dirname "$__comp_cache")"
printf '%s' "$_out" > "${__comp_cache}.tmp"
mv "${__comp_cache}.tmp" "$__comp_cache"
) &
disown
# First run: no cache yet, source it once background job finishes
if [[ ! -f "$__comp_cache" ]]; then
__comp_deferred() {
if [[ -f "$__comp_cache" ]]; then
source "$__comp_cache"
PROMPT_COMMAND="${PROMPT_COMMAND/__comp_deferred;/}"
unset -f __comp_deferred
fi
}
PROMPT_COMMAND="__comp_deferred;${PROMPT_COMMAND:-}"
fi
# urfave/cli tools (cheap — no subprocess, loaded synchronously)
__comp_urfave=(tea drone)
for __comp_cmd in "${__comp_urfave[@]}"; do
if command -v "$__comp_cmd" &>/dev/null; then
eval "_${__comp_cmd}_bash_autocomplete() {
local cur opts
COMPREPLY=()
cur=\"\${COMP_WORDS[COMP_CWORD]}\"
opts=\$( \"\${COMP_WORDS[@]:0:\$COMP_CWORD}\" --generate-bash-completion 2>/dev/null )
COMPREPLY=( \$(compgen -W \"\${opts}\" -- \"\${cur}\") )
}"
complete -o default -F "_${__comp_cmd}_bash_autocomplete" "$__comp_cmd"
fi
done
unset __comp_cmd __comp_urfave