Created
February 24, 2021 22:50
-
-
Save alicek106/57eaf0205b8984f0b0b514b57351a75e to your computer and use it in GitHub Desktop.
Terraform workspace prompt in shell (bash, zsh, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tf_prompt_info() { | |
# dont show 'default' workspace in home dir | |
[[ "$PWD" == ~ ]] && return | |
# check if in terraform dir | |
if [ -d .terraform ]; then | |
# Most of scripts uses 'terraform workspace show' but it's too slow in some cases. | |
# We can just bring out the environment file to bash | |
if [ -f .terraform/environment ]; then | |
workspace=$(cat .terraform/environment 2> /dev/null) || return | |
echo "[${workspace}]" | |
else | |
echo "[default]" | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment