This repository provides gcproj
script that lets you quickly see all GCP
projects and switch between them. Heavily influenced by kubectx
.
gcloud
is installed- User is authenticated with any GCP project
gcloud auth
- Optional:
fzf
for fuzzy-finding and interactive mode
List all projects available for your current account. Just runs
gcloud projects list
.
$ gcproj
PROJECT_ID NAME PROJECT_NUMBER
foo-1234 foo 123456789
bar-5678 bar 567891234
Runs gcloud config set project
for the specified project. It will output any
messages that comes from gcloud config set project
command as is.
$ gcproj foo-1234
Updated property [core/project].
Getting the list of projects, even for accounts with a small list of projects,
takes significant amount of time. In order to help with startup times, gcproj
caches the list of projects. By default, the cache is refreshed once a day.
The cache is stored in $XDG_CACHE_HOME/gcproj/projects
file. If $XDG_CACHE_HOME
is not defined, then the cache is stored in $HOME/.cache/gcproj/projects
.
The projects list is refreshed if the cache is stale. By default, the cache is
valid for 1 day. The cache TTL can be configured with the $GCPROJ_CACHE_TTL
,
environment variable. The value of $GCPROJ_CACHE_TTL
is in seconds, defaults
to 1 day, aka 86400
seconds.
The cache can be refreshed with the --refresh
flag.
Incldue gcproj
in your $PATH
.
If you have fzf
installed, you can
interactively select a project or fuzzy-search.
- bash completion
- zsh completion
- Add gif for fzf/interactive mode to README
- Ignore
fzf
- CI and automate linting etc
-
Cache list of projects to improve startup time -
Switch to previous projectgcproj -