gcloud-switch

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT

README

gcloud-switch (gctx)

kubectx for gcloud configurations. Fast, native switching between gcloud config configurations — no Python cold-start.

gctx reads and writes gcloud's config files directly (~/.config/gcloud/configurations/ and active_config), so switching is instant.

Install

brew install kostyay/tap/gctx

Or with Go:

go install github.com/kostyay/gcloud-switch/cmd/gctx@latest

Usage

gctx                    # fuzzy-pick a configuration to activate (with preview)
gctx <name>             # activate <name>
gctx -                  # activate the previous configuration
gctx -c                 # print the active configuration
gctx rename <old> <new> # rename a configuration
gctx -h                 # help

The no-arg picker marks the currently active configuration, and flags any whose credentials need a re-login with (login required). Each item's preview shows its account, project, region, and its login_config_file when set. Switching is global — it changes gcloud's active configuration for every shell, exactly like gcloud config configurations activate.

Auth check

After switching, gctx verifies the new configuration's credentials by attempting a token refresh directly (no gcloud subprocess). If the credentials are expired — common with Workforce Identity Federation / BeyondCorp configs that require a browser re-login — it prints the exact login command and offers to run it:

Credentials for "acme-prod" (principal://…) are expired.
Re-login with: gcloud auth login --login-config=/path/to/login-config.json
Re-login now? [y/N]

The command uses the configuration's [auth] login_config_file when set. If that file is missing (for example, it was written to a temp path that has since been cleared), gctx reports the dangling path and shows the command to repoint the configuration instead of running a login that would fail. A configuration with no account set is never flagged — there is nothing to authenticate.

Configuration

gctx honors CLOUDSDK_CONFIG for the gcloud config root, falling back to ~/.config/gcloud. Its own state (the "previous" configuration) is stored under $XDG_CONFIG_HOME/gcloud-switch/ (or ~/.config/gcloud-switch/).

License

MIT — see LICENSE.

Directories

Path Synopsis
cmd
gctx command
Command gctx switches the active gcloud configuration, kubectx-style.
Command gctx switches the active gcloud configuration, kubectx-style.
internal
env
Package env resolves filesystem paths from environment variables, keeping environment lookups out of business logic.
Package env resolves filesystem paths from environment variables, keeping environment lookups out of business logic.
gcloud
Package gcloud is the sole interface for gcloud CLI configuration state.
Package gcloud is the sole interface for gcloud CLI configuration state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL