Created
January 11, 2018 16:07
-
-
Save rmwpl/74d5f21d37a507bb5f387e1dec82afa5 to your computer and use it in GitHub Desktop.
Terraform bash prompt, to be used with bash-git-prompt
This file contains 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
#!/bin/bash | |
__terraform_ps1() | |
{ | |
# get current workspace | |
WORKSPACE=$(terraform workspace show) | |
if $(pwd | /bin/grep -q 'terraform'); then | |
if [ -n "$WORKSPACE" ]; then | |
echo -ne "${White}(terraform: " | |
[ "${WORKSPACE}" == "production" ] && echo -ne "${BoldRed}" || echo -ne "${Green}" | |
echo -e "${WORKSPACE}${White})${ResetColor}" | |
fi | |
fi | |
} |
You can add it to your ~/.bash_profile. Just rename it from "__terraform_ps1()" to "prompt_callback()"
And terraform supports the $TF_WORKSPACE variable, so you should change:
WORKSPACE=$(terraform workspace show)
to
WORKSPACE=${TF_WORKSPACE:-$(terraform workspace show)}
And lastly, I like to add this first to include the path:
gp_truncate_pwd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to configure bash-git-prompt to also load this shell script?