Skip to content

Instantly share code, notes, and snippets.

@alicek106
Created February 24, 2021 22:50
Show Gist options
  • Save alicek106/57eaf0205b8984f0b0b514b57351a75e to your computer and use it in GitHub Desktop.
Save alicek106/57eaf0205b8984f0b0b514b57351a75e to your computer and use it in GitHub Desktop.
Terraform workspace prompt in shell (bash, zsh, etc.)
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