Switch Google Cloud configurations instantly.
gsw is a lightweight Bash/Zsh plugin that makes switching between Google Cloud SDK configurations effortless. It defaults to Session switching (changing only for the current terminal tab), with an option for Global switching.
Managing multiple Google Cloud projects usually involves gcloud config configurations activate ..., which changes the global state. This becomes dangerous when you have multiple terminals open—running a command in one terminal might target the wrong project because you switched configs in another tab.
| Feature | gsw |
gcloud activate |
direnv |
|---|---|---|---|
| Scope | Session (Current tab) | Global (All tabs) | Directory-based |
| Switching | Ad-hoc (Anywhere) | Ad-hoc (Anywhere) | Automatic (On cd) |
| Safety | High (Isolated) | Low (Side effects) | High (Context-aware) |
| Setup | Zero | Zero | Needs .envrc files |
gsw is a clean wrapper around the CLOUDSDK_ACTIVE_CONFIG_NAME environment variable. When you run gsw <config>, it exports this variable to your current shell session. Since the Google Cloud SDK honors this variable over the global configuration, you get instant, safe isolation without any complex magic.
- 🛡️ Session Isolation:
gsw <config>switches only in the current terminal tab (perfect for multi-project workflows). - ⚡ Global Switch:
gsw -g <config>to switch globally when needed. - 🧠 Auto-Completion: Tab completion for your existing gcloud configurations (Bash & Zsh).
- 📦 Zero Dependencies: Pure Shell functions.
gsw is just a shell script. Choose the method that fits your workflow.
If you use a plugin manager, this is the cleanest way to keep gsw updated.
zplug:
zplug "sakebook/gsw", use:gsw.shsheldon:
[plugins.gsw]
github = "sakebook/gsw"
use = ["gsw.sh"]- Clone the repo:
git clone https://github.com/sakebook/gsw.git ~/.gsw - Add this to your
~/.zshrc(or~/.bashrc):source ~/.gsw/gsw.sh
Run this command to install gsw to ~/.gsw and update your .zshrc automatically:
curl -sL https://raw.githubusercontent.com/sakebook/gsw/main/install.sh | bashChanges the active configuration only for the current shell session. This sets the CLOUDSDK_ACTIVE_CONFIG_NAME environment variable.
gsw my-work-profileChanges the active configuration for all open terminals.
gsw -g my-personal-profileJust run gsw without arguments to see available configurations and usage help.
gswMIT
