Skip to content

Instantly share code, notes, and snippets.

@rmwpl
Created January 11, 2018 16:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmwpl/74d5f21d37a507bb5f387e1dec82afa5 to your computer and use it in GitHub Desktop.
Save rmwpl/74d5f21d37a507bb5f387e1dec82afa5 to your computer and use it in GitHub Desktop.
Terraform bash prompt, to be used with bash-git-prompt
#!/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
}
@kevcodez
Copy link

How to configure bash-git-prompt to also load this shell script?

@mbordas09
Copy link

mbordas09 commented Oct 28, 2018

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