Manage gcloud configurations the way nvm and
rbenv manage language versions: switch the
active profile per-shell, set a global default, and auto-switch based on a
.gcloudenv file in your project.
gcloudenv is a thin layer over gcloud config configurations — gcloud remains
the source of truth for accounts, projects, and credentials. gcloudenv just
makes switching between them ergonomic and shell-aware.
A child process can't change its parent shell's environment, so gcloudenv
ships a small shell function (the shim) that evals the export lines the
binary prints. Switching a profile sets CLOUDSDK_ACTIVE_CONFIG_NAME, which
gcloud reads to pick the active configuration for that shell — no global state
touched.
With Go:
go install github.com/figverse/gcloudenv@latestOr grab a prebuilt binary for your platform from the releases page.
Then add the integration to your shell rc:
# ~/.zshrc or ~/.bashrc
eval "$(gcloudenv init zsh)"
# fish: ~/.config/fish/config.fish
gcloudenv init fish | sourcegcloudenv list # all profiles; * marks the active one
gcloudenv use staging # switch this shell to "staging"
gcloudenv use prod --global # change gcloud's global default
gcloudenv current # show active profile + account/project + source
gcloudenv create staging \ # create a profile and seed it
--account me@x.com --project my-stg
gcloudenv local staging # write .gcloudenv so this dir auto-switches
gcloudenv adc login staging # give this profile its own ADC for SDKs
gcloudenv adc status # show which profiles have isolated ADCgcloudenv local <profile> writes a .gcloudenv file (like .nvmrc). With the
shim installed, cd-ing into that directory (or any child) switches the shell
to that profile automatically. Resolution precedence, highest first:
- explicit argument (
gcloudenv use X) - nearest
.gcloudenvwalking up from the cwd $CLOUDSDK_ACTIVE_CONFIG_NAMEalready in the environment- gcloud's own global default
gcloud configurations isolate the CLI's account and project, but client libraries (the Go/Python/etc. SDKs, Terraform, ...) read Application Default Credentials from a single shared file — so by default they can't tell profiles apart.
gcloudenv adc login <profile> gives a profile its own ADC. It runs
gcloud auth application-default login in isolation and stores the result at
<gcloud-config>/profiles/<profile>/application_default_credentials.json
(<gcloud-config> is $CLOUDSDK_CONFIG, else ~/.config/gcloud), creating the
directory if needed. The shared well-known ADC file is never touched.
Once stored, switching to that profile also exports
GOOGLE_APPLICATION_CREDENTIALS, which client libraries honor ahead of the
well-known file. Switching to a profile without stored ADC unsets the
variable, so SDKs fall back to gcloud's shared ADC rather than leaking the
previous profile's identity — i.e. once you adopt per-profile ADC, gcloudenv
owns GOOGLE_APPLICATION_CREDENTIALS in shells where it switches profiles.
make build # build ./gcloudenv
make test # run unit tests (no real gcloud needed — uses a stub)
make check # fmt-check + vet + lint + test, as CI runs themTests run against a stub gcloud, so they're safe to run anywhere.
Contributions are welcome! See CONTRIBUTING.md for setup, conventions, and the PR checklist, and please follow our Code of Conduct. Security issues should be reported per SECURITY.md.
MIT © Figverse