THE PROBLEM: GLOBAL CONTEXT COLLISION
The standard way to switch configurations in GCP is "gcloud config configurations activate ". However, this changes the GLOBAL state of the SDK. If you have several terminal tabs open---perhaps one for Production logs and another for a Staging deploy---switching the configuration in one tab silently changes it for all others. It's too easy to accidentally run a destructive command in the wrong environment.
THE SOLUTION: SESSION-SCOPED SWITCHING
gsw leverages the CLOUDSDK_ACTIVE_CONFIG_NAME environment variable to isolate configuration changes to the CURRENT shell session only.
gsw : Switches the current tab (Safe by default). gsw -g : Switches globally when you actually need it. WHY NOT JUST USE DIRENV OR ALIASES?
vs direnv: direnv is great for directory-specific settings. gsw is for ad-hoc, manual switching regardless of where you are in your filesystem. vs aliases: Managing dozens of projects with aliases gets messy. gsw gives you dynamic tab-completion based on your actual gcloud configurations. KEY FEATURES
KISS approach: No binaries, no heavy dependencies. Just a few shell functions that wrap environment variables. Developer Experience: Fast, interactive tab-completion for both Bash and Zsh. Safety First: Running gsw without arguments lists your configs and highlights who you are and what is active. GET STARTED
It is just one shell file. You can install it manually or via plugin managers to keep it clean.
GitHub: https://github.com/sakebook/gsw
I'd love to hear how you manage your cloud contexts or any feedback on making this even safer!