Current Juju Environment Name in Bash Prompt

Having to test code in multiple Juju providers one can forget which environment you’re currently working on. So yesterday I came up with this little snippet in my $HOME/.bashrc file:

This gives you a nice prompt like this:

[local] user@host:~$
# when "local" is bootstrapped:
[local] user@host:~$

It assumes you have your Juju home directory in $HOME/.juju or set using the $JUJU_HOME environment variable. Then it checks whether $JUJU_ENV is set and uses that. Otherwise, it looks for the current-environment file juju switch command creates. Finally, as a fallback it calls calls juju switch.

A nice feature is that you’ll see local┬áin light gray if the environment is not bootstrapped, or in green othewise (thanks for the tip Simon Davy and for the bug fix!). You can tell whether it’s bootstrapped by the existence of a $JUJU_HOME/environments/<name>.jenv file, which is created after bootstrap.

Now I just need to set up AWS billing alert on my Amazon account, so that next time I forget to destroy a live testing environment on EC2, the bill won’t be outrageous :/



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Powered by: Wordpress