* Added new module for showing in prompt the active terraform version.

* Prompt shows, the terraform version in this format: Terraform v0.12.13 . If only if a valid terraform command is used, or an alias to it.

The use case: We have a need to constantly change between terraform versions depending on what project we are working on, it is easy to by mistake upgrade the wrong project to the latest terraform version. This is why the prompt is shown in red as soon as you type terraform, this is a good way to remind you to double check this is the terraform version you want to use.

Future improvements:
Detect current terraform version by checking the terraform workspace state version, and change the terraform color prompt from red to green if you're using the same version.
pull/1487/head
Alejandro Gandara 3 years ago
parent 1e7be00e04
commit f717a91f55

@ -70,6 +70,7 @@
haskell_stack # haskell version from stack (https://haskellstack.org/) haskell_stack # haskell version from stack (https://haskellstack.org/)
kubecontext # current kubernetes context (https://kubernetes.io/) kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io) terraform # terraform workspace (https://www.terraform.io)
terraform_version # It shows current active terraform version
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)

@ -70,6 +70,7 @@
haskell_stack # haskell version from stack (https://haskellstack.org/) haskell_stack # haskell version from stack (https://haskellstack.org/)
kubecontext # current kubernetes context (https://kubernetes.io/) kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io) terraform # terraform workspace (https://www.terraform.io)
terraform_version # It shows current active terraform version
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)

@ -70,6 +70,7 @@
haskell_stack # haskell version from stack (https://haskellstack.org/) haskell_stack # haskell version from stack (https://haskellstack.org/)
kubecontext # current kubernetes context (https://kubernetes.io/) kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io) terraform # terraform workspace (https://www.terraform.io)
terraform_version # It shows current active terraform version
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)

@ -70,6 +70,7 @@
haskell_stack # haskell version from stack (https://haskellstack.org/) haskell_stack # haskell version from stack (https://haskellstack.org/)
kubecontext # current kubernetes context (https://kubernetes.io/) kubecontext # current kubernetes context (https://kubernetes.io/)
terraform # terraform workspace (https://www.terraform.io) terraform # terraform workspace (https://www.terraform.io)
terraform_version # It shows current active terraform version
aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) aws # aws profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html)
aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/) aws_eb_env # aws elastic beanstalk environment (https://aws.amazon.com/elasticbeanstalk/)
azure # azure account name (https://docs.microsoft.com/en-us/cli/azure) azure # azure account name (https://docs.microsoft.com/en-us/cli/azure)

@ -4887,6 +4887,15 @@ _p9k_prompt_terraform_init() {
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[terraform]' typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[terraform]'
} }
function prompt_terraform_version() {
local terraform_version="$(command terraform --version)"
_p9k_prompt_segment "$0$state" $_p9k_color1 red TERRAFORM_ICON 0 '' $terraform_version
}
_p9k_prompt_terraform_version_init() {
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='$commands[terraform]'
}
function prompt_proxy() { function prompt_proxy() {
local -U p=( local -U p=(
$all_proxy $http_proxy $https_proxy $ftp_proxy $all_proxy $http_proxy $https_proxy $ftp_proxy

Loading…
Cancel
Save