Skip to content

Repository files navigation

azenv

azenv gives Azure CLI named, per-shell contexts by isolating AZURE_CONFIG_DIR per context.

It does not replace az. It only manages which Azure CLI config directory your current shell uses.

Install

With Homebrew:

brew install lognseth/tap/azenv

Or tap the repository first:

brew tap lognseth/tap
brew install azenv

Install from source

For a manual install from a local checkout:

./install.sh

By default this installs to ~/.local/bin/azenv.

For zsh, make sure ~/.local/bin is on your PATH:

mkdir -p ~/.local/bin
export PATH="$HOME/.local/bin:$PATH"

Add that PATH line to ~/.zshrc if it is not already there.

To install to /usr/local/bin instead:

./install.sh --system

Shell integration

For zsh:

eval "$(azenv init zsh)"

Put that in ~/.zshrc after installing the binary. This defines a shell function so azenv use <context> can update AZURE_CONFIG_DIR in the current terminal.

For bash:

eval "$(azenv init bash)"

For fish:

azenv init fish | source

Shell completions are generated by Cobra:

azenv completion zsh > ~/.zfunc/_azenv

Usage

Create a context:

azenv create dev

Activate it in the current zsh terminal:

azenv use dev
echo $AZURE_CONFIG_DIR
azenv current

If azenv use dev prints export AZURE_CONFIG_DIR=... instead of switching, load the shell integration first:

eval "$(azenv init zsh)"

Create a context and log in immediately:

azenv create prod --login

Or log in later:

azenv login prod

Activate it in the current terminal:

azenv use prod

Set the subscription once:

az account set -s <subscription-id-or-name>

Next time, just run:

azenv use prod

Run azenv use with no arguments to select a context with fzf.

List contexts:

azenv ls

The active context is marked with *.

Show current context and Azure account:

azenv current

Run a single command in another context without switching the current shell:

azenv exec prod -- az account show
azenv exec staging -- terraform plan
azenv exec prod -- terraform apply

Clone or rename a context:

azenv clone prod prod-copy
azenv rename prod-copy sandbox

Log out of a context:

azenv logout prod

Check your local setup:

azenv doctor

Remove a context:

azenv rm prod

Storage

By default, contexts live here:

~/.config/azenv/
  config.yaml
  contexts/
    prod/
      azure/
      metadata.yaml

Override with:

export AZENV_HOME="$HOME/.azenv"

Then contexts live under:

$AZENV_HOME/
  config.yaml
  contexts/<name>/azure/

metadata.yaml stores friendly details such as subscription name, tenant, user, and last-used time. azenv refreshes this metadata best-effort from the Azure CLI after use and login.

Starship

azenv can print a Starship custom module config:

azenv starship init

Add the output to ~/.config/starship.toml.

Notes

A standalone program cannot directly change the parent shell environment. That is why azenv use needs the shell integration from azenv init. The wrapper evaluates the export statements emitted by the binary.

Release Notes

See CHANGELOG.md.

License

MIT. See LICENSE.

About

azenv is a tiny utility that makes it easy to add multiple Azure CLI context directories and switch between them.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages