From 20b87731de26638f40dce1bfc89f5b5a207e090f Mon Sep 17 00:00:00 2001 From: Patrick Tavares Date: Mon, 16 Aug 2021 18:46:46 +0200 Subject: [PATCH 1/2] add availability to display or not Terraform version Show Terraform version segment only when *.tf files are present in current directory --- config/p10k-classic.zsh | 2 ++ config/p10k-lean-8colors.zsh | 2 ++ config/p10k-lean.zsh | 2 ++ config/p10k-rainbow.zsh | 2 ++ internal/p10k.zsh | 5 ++++- 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/p10k-classic.zsh b/config/p10k-classic.zsh index 592d8a7..3ccd335 100644 --- a/config/p10k-classic.zsh +++ b/config/p10k-classic.zsh @@ -1206,6 +1206,8 @@ # typeset -g POWERLEVEL9K_TERRAFORM_OTHER_VISUAL_IDENTIFIER_EXPANSION='⭐' #############[ terraform_version: terraform version (https://www.terraform.io) ]############## + # Don't show terraform version if there is no "*.tf" files + typeset -g POWERLEVEL9K_TERRAFORM_VERSION_ALWAYS=false # Terraform version color. typeset -g POWERLEVEL9K_TERRAFORM_VERSION_FOREGROUND=38 # Custom icon. diff --git a/config/p10k-lean-8colors.zsh b/config/p10k-lean-8colors.zsh index 8e98757..123a42c 100644 --- a/config/p10k-lean-8colors.zsh +++ b/config/p10k-lean-8colors.zsh @@ -1274,6 +1274,8 @@ # typeset -g POWERLEVEL9K_TERRAFORM_OTHER_VISUAL_IDENTIFIER_EXPANSION='⭐' #############[ terraform_version: terraform version (https://www.terraform.io) ]############## + # Don't show terraform version if there is no "*.tf" files + typeset -g POWERLEVEL9K_TERRAFORM_VERSION_ALWAYS=false # Terraform version color. typeset -g POWERLEVEL9K_TERRAFORM_VERSION_FOREGROUND=4 # Custom icon. diff --git a/config/p10k-lean.zsh b/config/p10k-lean.zsh index 5bfd77c..698ffa7 100644 --- a/config/p10k-lean.zsh +++ b/config/p10k-lean.zsh @@ -1270,6 +1270,8 @@ # typeset -g POWERLEVEL9K_TERRAFORM_OTHER_VISUAL_IDENTIFIER_EXPANSION='⭐' #############[ terraform_version: terraform version (https://www.terraform.io) ]############## + # Don't show terraform version if there is no "*.tf" files + typeset -g POWERLEVEL9K_TERRAFORM_VERSION_ALWAYS=false # Terraform version color. typeset -g POWERLEVEL9K_TERRAFORM_VERSION_FOREGROUND=38 # Custom icon. diff --git a/config/p10k-rainbow.zsh b/config/p10k-rainbow.zsh index a580f30..1535cb3 100644 --- a/config/p10k-rainbow.zsh +++ b/config/p10k-rainbow.zsh @@ -1273,6 +1273,8 @@ # typeset -g POWERLEVEL9K_TERRAFORM_OTHER_VISUAL_IDENTIFIER_EXPANSION='⭐' #############[ terraform_version: terraform version (https://www.terraform.io) ]############## + # Don't show terraform version if there is no "*.tf" files + typeset -g POWERLEVEL9K_TERRAFORM_VERSION_ALWAYS=false # Terraform version color. typeset -g POWERLEVEL9K_TERRAFORM_VERSION_FOREGROUND=4 typeset -g POWERLEVEL9K_TERRAFORM_VERSION_BACKGROUND=0 diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 2099c32..2e1fa9e 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -3,7 +3,7 @@ if [[ $__p9k_sourced != 13 ]]; then >&2 print -P "[%F{1}ERROR%f]: Corrupted powerlevel10k installation." >&2 print -P "" if (( ${+functions[antigen]} )); then - >&2 print -P "If using %Bantigen%b, run the folowing command to fix:" + >&2 print -P "If using %Bantigen%b, run the following command to fix:" >&2 print -P "" >&2 print -P " %F{2}antigen%f reset" if [[ -d ~/.antigen ]]; then @@ -4888,6 +4888,9 @@ _p9k_prompt_terraform_init() { } function prompt_terraform_version() { + if [[ $_POWERLEVEL9K_TERRAFORM_VERSION_ALWAYS ]]; then + _p9k_upglob "*.tf" && return 1 + fi _p9k_cached_cmd 0 '' terraform --version || return local v=${_p9k__ret#Terraform v} (( $#v < $#_p9k__ret )) || return From 6aeb13b08aab0b35f0c9b0212f1c0cba89eaa5d3 Mon Sep 17 00:00:00 2001 From: Patrick Tavares Date: Mon, 16 Aug 2021 18:47:40 +0200 Subject: [PATCH 2/2] add terraform_version segment to the list of available segments --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ddff77f..679c4f0 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,7 @@ enable as many segments as you like. It won't slow down your prompt or Zsh start | `package` | `name@version` from [package.json](https://docs.npmjs.com/files/package.json) | | `kubecontext` | current [kubernetes](https://kubernetes.io/) context | | `terraform` | [terraform](https://www.terraform.io) workspace | +| `terraform_version` | [terraform](https://www.terraform.io) version | | `aws` | [aws profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) | | `aws_eb_env` | [aws elastic beanstalk](https://aws.amazon.com/elasticbeanstalk/) environment | | `azure` | [azure](https://docs.microsoft.com/en-us/cli/azure) account name |