Juju

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 :/

Share

4 Comments

  • Nick Veitch
    February 26, 2014 - 13:28 | Permalink

    Neat. Does this correctly detect the edge case when there is a current-environment file but it has been overridden by setting the $JUJU_ENV?

  • dimitern
    February 26, 2014 - 13:40 | Permalink

    Ah, that’s a good point! I forgot about that. Will update the snippet. Thanks Nick!

  • Simon Davy
    February 27, 2014 - 22:53 | Permalink

    Line 15 has a missing $ before the {

    Good work!

    I added ansi colors to mine to indicate bootstrapped or not

    • dimitern
      February 28, 2014 - 14:58 | Permalink

      Thanks Simon!

      I’ve updated the snippet to include ANSI colors, although green and gray, rather than red (it reads better on my semi-translucent deep purple terminal background).

      I also fixed the missing $ – the plain text code was correct, but it turned out the Crayon syntax highlighter plugin somehow interpreted /${currentEnv} specially and dropped the $ from the displayed text (it is even doing it now – I had to edit this comment a few times).

  • Leave a Reply

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

    Powered by: Wordpress