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.
brew install kostyay/tap/gctxOr with Go:
go install github.com/kostyay/gcloud-switch/cmd/gctx@latestgctx # 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 # helpThe 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.
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.
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/).
MIT — see LICENSE.