From fd8f72b27614d48ec06421fb80aff2eb10674a69 Mon Sep 17 00:00:00 2001 From: chenzj Date: Sun, 14 Jul 2024 01:31:32 +0800 Subject: feat(opentofu): add plugin for OpenTofu (#12285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Adds aliases - Sets up autocompletion - Adds promp functions to show workspace and `tofu` version Co-authored-by: Marc Cornellà --- plugins/opentofu/opentofu.plugin.zsh | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 plugins/opentofu/opentofu.plugin.zsh (limited to 'plugins/opentofu/opentofu.plugin.zsh') diff --git a/plugins/opentofu/opentofu.plugin.zsh b/plugins/opentofu/opentofu.plugin.zsh new file mode 100644 index 000000000..c6844c84a --- /dev/null +++ b/plugins/opentofu/opentofu.plugin.zsh @@ -0,0 +1,43 @@ +# set up the tofu completion (compatible for zsh) +autoload -Uz bashcompinit && bashcompinit +complete -C tofu tofu + +# tofu workspace prompt function +function tofu_prompt_info() { + # only show the workspace name if we're in an opentofu project + # i.e. if a .terraform directory exists within the hierarchy + local dir="$PWD" + while [[ ! -d "${dir}/.terraform" ]]; do + [[ "$dir" != / ]] || return 0 # stop at the root directory + dir="${dir:h}" # get the parent directory + done + + # workspace might be different than the .terraform/environment file + # for example, if set with the TF_WORKSPACE environment variable + local workspace="$(tofu workspace show)" + # make sure to escape % signs in the workspace name to prevent command injection + echo "${ZSH_THEME_TOFU_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TOFU_PROMPT_SUFFIX-]}" +} + +# tofu version prompt function +function tofu_version_prompt_info() { + # get the output of `tofu --version` in a single line, and get the second word after splitting by a space + local tofu_version=${${(s: :)$(tofu --version)}[2]} + # make sure to escape % signs in the version string to prevent command injection + echo "${ZSH_THEME_TOFU_VERSION_PROMPT_PREFIX-[}${tofu_version:gs/%/%%}${ZSH_THEME_TOFU_VERSION_PROMPT_SUFFIX-]}" +} + +alias tt='tofu' +alias tta='tofu apply' +alias ttc='tofu console' +alias ttd='tofu destroy' +alias ttf='tofu fmt' +alias tti='tofu init' +alias tto='tofu output' +alias ttp='tofu plan' +alias ttv='tofu validate' +alias tts='tofu state' +alias ttsh='tofu show' +alias ttr='tofu refresh' +alias ttt='tofu test' +alias ttws='tofu workspace' -- cgit v1.2.3-70-g09d2 From e6380085f3bc917d913e2d9ddf79a03a09ad95fc Mon Sep 17 00:00:00 2001 From: michael-follmann <35061945+michael-follmann@users.noreply.github.com> Date: Thu, 5 Sep 2024 19:52:39 +0200 Subject: feat(terraform): add `fmt -recursive` alias (#12637) --- plugins/opentofu/README.md | 33 +++++++++++++++++---------------- plugins/opentofu/opentofu.plugin.zsh | 1 + plugins/terraform/README.md | 31 ++++++++++++++++--------------- plugins/terraform/terraform.plugin.zsh | 1 + 4 files changed, 35 insertions(+), 31 deletions(-) (limited to 'plugins/opentofu/opentofu.plugin.zsh') diff --git a/plugins/opentofu/README.md b/plugins/opentofu/README.md index 9c19501aa..9811e2751 100644 --- a/plugins/opentofu/README.md +++ b/plugins/opentofu/README.md @@ -15,22 +15,23 @@ plugins=(... opentofu) ## Aliases -| Alias | Command | -| ----- | --------------- | -| `tt` | `tofu` | -| `tta` | `tofu apply` | -| `ttc` | `tofu console` | -| `ttd` | `tofu destroy` | -| `ttf` | `tofu fmt` | -| `tti` | `tofu init` | -| `tto` | `tofu output` | -| `ttp` | `tofu plan` | -| `ttv` | `tofu validate` | -| `tts` | `tofu state` | -| `ttsh`| `tofu show` | -| `ttr` | `tofu refresh` | -| `ttt` | `tofu test` | -| `ttws`| `tofu workspace`| +| Alias | Command | +|--------|-----------------------| +| `tt` | `tofu` | +| `tta` | `tofu apply` | +| `ttc` | `tofu console` | +| `ttd` | `tofu destroy` | +| `ttf` | `tofu fmt` | +| `ttfr` | `tofu fmt -recursive` | +| `tti` | `tofu init` | +| `tto` | `tofu output` | +| `ttp` | `tofu plan` | +| `ttv` | `tofu validate` | +| `tts` | `tofu state` | +| `ttsh` | `tofu show` | +| `ttr` | `tofu refresh` | +| `ttt` | `tofu test` | +| `ttws` | `tofu workspace` | ## Prompt functions diff --git a/plugins/opentofu/opentofu.plugin.zsh b/plugins/opentofu/opentofu.plugin.zsh index c6844c84a..aa6cac78a 100644 --- a/plugins/opentofu/opentofu.plugin.zsh +++ b/plugins/opentofu/opentofu.plugin.zsh @@ -32,6 +32,7 @@ alias tta='tofu apply' alias ttc='tofu console' alias ttd='tofu destroy' alias ttf='tofu fmt' +alias ttfr='tofu fmt -recursive' alias tti='tofu init' alias tto='tofu output' alias ttp='tofu plan' diff --git a/plugins/terraform/README.md b/plugins/terraform/README.md index b5158b4e9..ca5a771bc 100644 --- a/plugins/terraform/README.md +++ b/plugins/terraform/README.md @@ -15,21 +15,22 @@ plugins=(... terraform) ## Aliases -| Alias | Command | -| ------ | ------------------------- | -| `tf` | `terraform` | -| `tfa` | `terraform apply` | -| `tfc` | `terraform console` | -| `tfd` | `terraform destroy` | -| `tff` | `terraform fmt` | -| `tfi` | `terraform init` | -| `tfiu` | `terraform init -upgrade` | -| `tfo` | `terraform output` | -| `tfp` | `terraform plan` | -| `tfv` | `terraform validate` | -| `tfs` | `terraform state` | -| `tft` | `terraform test` | -| `tfsh` | `terraform show` | +| Alias | Command | +|--------|----------------------------| +| `tf` | `terraform` | +| `tfa` | `terraform apply` | +| `tfc` | `terraform console` | +| `tfd` | `terraform destroy` | +| `tff` | `terraform fmt` | +| `tffr` | `terraform fmt -recursive` | +| `tfi` | `terraform init` | +| `tfiu` | `terraform init -upgrade` | +| `tfo` | `terraform output` | +| `tfp` | `terraform plan` | +| `tfv` | `terraform validate` | +| `tfs` | `terraform state` | +| `tft` | `terraform test` | +| `tfsh` | `terraform show` | ## Prompt function diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index 71a58b939..181f57b9b 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -20,6 +20,7 @@ alias tfa='terraform apply' alias tfc='terraform console' alias tfd='terraform destroy' alias tff='terraform fmt' +alias tffr='terraform fmt -recursive' alias tfi='terraform init' alias tfiu='terraform init -upgrade' alias tfo='terraform output' -- cgit v1.2.3-70-g09d2 From dae5a4115917e2b9c65d9166c5d64df693f70dd4 Mon Sep 17 00:00:00 2001 From: za Date: Wed, 2 Oct 2024 15:49:31 +0700 Subject: feat(opentofu): add `apply -auto-approve` alias (#12714) --- plugins/opentofu/README.md | 35 ++++++++++++++++++----------------- plugins/opentofu/opentofu.plugin.zsh | 1 + 2 files changed, 19 insertions(+), 17 deletions(-) (limited to 'plugins/opentofu/opentofu.plugin.zsh') diff --git a/plugins/opentofu/README.md b/plugins/opentofu/README.md index 9811e2751..cc6e94acd 100644 --- a/plugins/opentofu/README.md +++ b/plugins/opentofu/README.md @@ -15,23 +15,24 @@ plugins=(... opentofu) ## Aliases -| Alias | Command | -|--------|-----------------------| -| `tt` | `tofu` | -| `tta` | `tofu apply` | -| `ttc` | `tofu console` | -| `ttd` | `tofu destroy` | -| `ttf` | `tofu fmt` | -| `ttfr` | `tofu fmt -recursive` | -| `tti` | `tofu init` | -| `tto` | `tofu output` | -| `ttp` | `tofu plan` | -| `ttv` | `tofu validate` | -| `tts` | `tofu state` | -| `ttsh` | `tofu show` | -| `ttr` | `tofu refresh` | -| `ttt` | `tofu test` | -| `ttws` | `tofu workspace` | +| Alias | Command | +|--------|------------------------------| +| `tt` | `tofu` | +| `tta` | `tofu apply` | +| `ttaa` | `tofu apply -auto-approve` | +| `ttc` | `tofu console` | +| `ttd` | `tofu destroy` | +| `ttf` | `tofu fmt` | +| `ttfr` | `tofu fmt -recursive` | +| `tti` | `tofu init` | +| `tto` | `tofu output` | +| `ttp` | `tofu plan` | +| `ttv` | `tofu validate` | +| `tts` | `tofu state` | +| `ttsh` | `tofu show` | +| `ttr` | `tofu refresh` | +| `ttt` | `tofu test` | +| `ttws` | `tofu workspace` | ## Prompt functions diff --git a/plugins/opentofu/opentofu.plugin.zsh b/plugins/opentofu/opentofu.plugin.zsh index aa6cac78a..79b102a74 100644 --- a/plugins/opentofu/opentofu.plugin.zsh +++ b/plugins/opentofu/opentofu.plugin.zsh @@ -29,6 +29,7 @@ function tofu_version_prompt_info() { alias tt='tofu' alias tta='tofu apply' +alias ttaa='tofu apply -auto-approve' alias ttc='tofu console' alias ttd='tofu destroy' alias ttf='tofu fmt' -- cgit v1.2.3-70-g09d2 From 7ce26a810d79fa65abdb6a9b47b64bed59f1eefc Mon Sep 17 00:00:00 2001 From: za Date: Thu, 3 Oct 2024 15:42:18 +0700 Subject: feat(opentofu): add `destroy -auto-approve` alias (#12719) --- plugins/opentofu/README.md | 1 + plugins/opentofu/opentofu.plugin.zsh | 1 + 2 files changed, 2 insertions(+) (limited to 'plugins/opentofu/opentofu.plugin.zsh') diff --git a/plugins/opentofu/README.md b/plugins/opentofu/README.md index cc6e94acd..56f116492 100644 --- a/plugins/opentofu/README.md +++ b/plugins/opentofu/README.md @@ -22,6 +22,7 @@ plugins=(... opentofu) | `ttaa` | `tofu apply -auto-approve` | | `ttc` | `tofu console` | | `ttd` | `tofu destroy` | +| `ttd!` | `tofu destroy -auto-approve` | | `ttf` | `tofu fmt` | | `ttfr` | `tofu fmt -recursive` | | `tti` | `tofu init` | diff --git a/plugins/opentofu/opentofu.plugin.zsh b/plugins/opentofu/opentofu.plugin.zsh index 79b102a74..bb65c12e3 100644 --- a/plugins/opentofu/opentofu.plugin.zsh +++ b/plugins/opentofu/opentofu.plugin.zsh @@ -32,6 +32,7 @@ alias tta='tofu apply' alias ttaa='tofu apply -auto-approve' alias ttc='tofu console' alias ttd='tofu destroy' +alias ttd!='tofu destroy -auto-approve' alias ttf='tofu fmt' alias ttfr='tofu fmt -recursive' alias tti='tofu init' -- cgit v1.2.3-70-g09d2 From 8a231b19308140ca88732e4cb0f3de9768036bfb Mon Sep 17 00:00:00 2001 From: Yurii Liaskovets Date: Wed, 17 Dec 2025 19:55:47 +0200 Subject: feat!: unify `auto-approve` aliases in `terraform` and `opentofu` (#12795) BREAKING CHANGE: `tfaa` (apply auto-approve) aliases are now named `tfa!` to require extra effort on potentially destructive action, in a similar fashion to destroy auto-approve. --- plugins/opentofu/README.md | 2 +- plugins/opentofu/opentofu.plugin.zsh | 2 +- plugins/terraform/README.md | 4 ++-- plugins/terraform/terraform.plugin.zsh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins/opentofu/opentofu.plugin.zsh') diff --git a/plugins/opentofu/README.md b/plugins/opentofu/README.md index 45b98c3c9..059664d47 100644 --- a/plugins/opentofu/README.md +++ b/plugins/opentofu/README.md @@ -19,7 +19,7 @@ plugins=(... opentofu) |--------|------------------------------| | `tt` | `tofu` | | `tta` | `tofu apply` | -| `ttaa` | `tofu apply -auto-approve` | +| `tta!` | `tofu apply -auto-approve` | | `ttc` | `tofu console` | | `ttd` | `tofu destroy` | | `ttd!` | `tofu destroy -auto-approve` | diff --git a/plugins/opentofu/opentofu.plugin.zsh b/plugins/opentofu/opentofu.plugin.zsh index bb65c12e3..b7a3ba3b6 100644 --- a/plugins/opentofu/opentofu.plugin.zsh +++ b/plugins/opentofu/opentofu.plugin.zsh @@ -29,7 +29,7 @@ function tofu_version_prompt_info() { alias tt='tofu' alias tta='tofu apply' -alias ttaa='tofu apply -auto-approve' +alias tta!='tofu apply -auto-approve' alias ttc='tofu console' alias ttd='tofu destroy' alias ttd!='tofu destroy -auto-approve' diff --git a/plugins/terraform/README.md b/plugins/terraform/README.md index f7a9a93dc..711139ef0 100644 --- a/plugins/terraform/README.md +++ b/plugins/terraform/README.md @@ -16,10 +16,10 @@ plugins=(... terraform) ## Aliases | Alias | Command | -| ------- | -------------------------------------- | +|---------|----------------------------------------| | `tf` | `terraform` | | `tfa` | `terraform apply` | -| `tfaa` | `terraform apply -auto-approve` | +| `tfa!` | `terraform apply -auto-approve` | | `tfap` | `terraform apply -parallelism=1` | | `tfc` | `terraform console` | | `tfd` | `terraform destroy` | diff --git a/plugins/terraform/terraform.plugin.zsh b/plugins/terraform/terraform.plugin.zsh index 9026994e4..1359ddd44 100644 --- a/plugins/terraform/terraform.plugin.zsh +++ b/plugins/terraform/terraform.plugin.zsh @@ -17,11 +17,11 @@ function tf_version_prompt_info() { alias tf='terraform' alias tfa='terraform apply' -alias tfaa='terraform apply -auto-approve' +alias tfa!='terraform apply -auto-approve' alias tfap='terraform apply -parallelism=1' alias tfc='terraform console' alias tfd='terraform destroy' -alias 'tfd!'='terraform destroy -auto-approve' +alias tfd!='terraform destroy -auto-approve' alias tfdp='terraform destroy -parallelism=1' alias tff='terraform fmt' alias tffr='terraform fmt -recursive' -- cgit v1.2.3-70-g09d2