mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
Refactor tofu_prompt_info, only show if in an OpenTofu project and use tofu workspace show
This commit is contained in:
parent
9634a024a3
commit
e87e913d1a
1 changed files with 12 additions and 6 deletions
|
|
@ -2,14 +2,20 @@
|
||||||
autoload -Uz bashcompinit && bashcompinit
|
autoload -Uz bashcompinit && bashcompinit
|
||||||
complete -C tofu tofu
|
complete -C tofu tofu
|
||||||
|
|
||||||
# tofu prompt functions
|
# tofu workspace prompt function
|
||||||
function tofu_prompt_info() {
|
function tofu_prompt_info() {
|
||||||
# dont show 'default' workspace in home dir
|
# only show the workspace name if we're in an opentofu project
|
||||||
[[ "$PWD" != ~ ]] || return
|
# i.e. if a .terraform directory exists within the hierarchy
|
||||||
# to keep compatibility with opentofu, the data dir names .terraform in OpenTofu
|
local dir="$PWD"
|
||||||
[[ -d .terraform && -r .terraform/environment ]] || return
|
while [[ ! -d "${dir}/.terraform" ]]; do
|
||||||
|
[[ "$dir" != / ]] || return 0 # stop at the root directory
|
||||||
|
dir="${dir:h}" # get the parent directory
|
||||||
|
done
|
||||||
|
|
||||||
local workspace="$(< .terraform/environment)"
|
# 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-]}"
|
echo "${ZSH_THEME_TOFU_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TOFU_PROMPT_SUFFIX-]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue