mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-12-02 05:13:03 +01:00
feat(terraform): add terraform-docs completion (#14185)
Generate completions from the installed terraform-docs CLI in the background and preserve a valid cache when generation fails or returns no output. Fixes #12138 AI-assisted with OpenAI Codex.
This commit is contained in:
1 parent
801782e8a6
commit
90f9fbc532
2 files changed
+28
No files matched your search
@@ -12,6 +12,14 @@ plugins=(... terraform)
|
|||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [Terraform](https://terraform.io/)
|
- [Terraform](https://terraform.io/)
|
||||||
|
- [terraform-docs](https://terraform-docs.io/) (optional, for completion)
|
||||||
|
|
||||||
|
## terraform-docs completion
|
||||||
|
|
||||||
|
If `terraform-docs` is installed, this plugin also enables its completion.
|
||||||
|
The completion script is generated from the installed version and cached in
|
||||||
|
`$ZSH_CACHE_DIR/completions/_terraform-docs`. It is refreshed in the background
|
||||||
|
each time the plugin loads, so completion stays in sync with the installed CLI.
|
||||||
|
|
||||||
## Aliases
|
## Aliases
|
||||||
|
|
||||||
|
|||||||
@@ -39,3 +39,23 @@ alias tfsh='terraform show'
|
|||||||
alias tfw='terraform workspace'
|
alias tfw='terraform workspace'
|
||||||
alias tfwl='terraform workspace list'
|
alias tfwl='terraform workspace list'
|
||||||
alias tfws='terraform workspace select'
|
alias tfws='terraform workspace select'
|
||||||
|
|
||||||
|
if (( $+commands[terraform-docs] )); then
|
||||||
|
# If the completion file doesn't exist yet, compinit hasn't registered it.
|
||||||
|
if [[ ! -f "$ZSH_CACHE_DIR/completions/_terraform-docs" ]]; then
|
||||||
|
typeset -g -A _comps
|
||||||
|
autoload -Uz _terraform-docs
|
||||||
|
_comps[terraform-docs]=_terraform-docs
|
||||||
|
fi
|
||||||
|
|
||||||
|
zmodload -F zsh/files b:zf_mv
|
||||||
|
() {
|
||||||
|
local completions
|
||||||
|
completions=$(command terraform-docs completion zsh) || return
|
||||||
|
[[ -n "$completions" ]] || return
|
||||||
|
|
||||||
|
local TMPPREFIX="$ZSH_CACHE_DIR/completions/._terraform-docs"
|
||||||
|
zf_mv -f -- =(print -r -- "$completions") \
|
||||||
|
"$ZSH_CACHE_DIR/completions/_terraform-docs"
|
||||||
|
} &|
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user