Repurpose gps as GCP project switcher#233
Draft
ikuwow wants to merge 2 commits into
Draft
Conversation
Switch gps from gcloud-configuration switching to per-shell project override via CLOUDSDK_CORE_PROJECT, mirroring the aps (AWS_PROFILE) pattern. Prompt indicator switches from <GC:config> to <GCP:project>. Co-authored-by: Claude Opus 4.7 <[email protected]>
- Capture gcloud projects list output before piping so failures (auth, network) propagate as exit 1 with a clear message instead of the misleading "No projects are selected." or empty --list output. - Drop the redundant Bash(gcloud projects list*) allow rule; the existing Bash(gcloud * list *) on line 89 already covers it. - Generalize the AIRULES.md GCP rule example to <gcloud|bq|gsutil> so the prefix template matches the scope the rule declares (verified bq and gsutil honor CLOUDSDK_CORE_PROJECT empirically). Co-authored-by: Claude Opus 4.7 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
gpsused to switch gcloudconfigurations, but only one real configuration ever existed (defaultfor[email protected]/mo-app-stg). The prompt showed<GC:default>regardless of which project was actually being targeted, leaving no safety signal when 50+ projects (stg vs prd) are all reachable from one account. That makes ops mistakes (e.g. running a prd command while thinking you're on stg) easy.The AWS side already solves the equivalent problem with
aps+AWS_PROFILE+prompt_aws: a per-shell env var, visible in the prompt, with a fzf switcher. This change aligns GCP to the same pattern, with the axis being GCP project (account is single-tenant today).Approach
gpsnow listsgcloud projects listvia fzf and exportsCLOUDSDK_CORE_PROJECTfor the current shell only. No disk state, no per-project configuration objects to maintain.gcloud projects listoutput is captured into a variable with an exit-status check before being piped, so auth / network failures surface asgps: failed to list GCP projects+ exit 1 instead of being swallowed by the pipe and producing a misleading "No projects are selected." message.prompt_gcshows<GCP:project-id>when the env var is set, empty otherwise. Empty is intentional — it signals "no override active, gcloud falls back to the default configuration's project."gcloud/bq/gsutilwithCLOUDSDK_CORE_PROJECT=<project>and confirm the project with the user before running.CLOUDSDK_CORE_PROJECTis the documented env override for[core] project(gcloud's section/property →CLOUDSDK_<SECTION>_<PROPERTY>convention). Same mechanism extends toCLOUDSDK_CORE_ACCOUNTwhen multi-account support is needed later — the switcher and prompt can be extended without changing the underlying contract.Out of scope
noneconfiguration that the oldgps --clearrelied on is no longer used. Cleanup is deliberately left for a separate PR.Verification
bash -c 'source .functions; gps --help'shows the new help textbash -c 'source .functions; CLOUDSDK_CORE_PROJECT=mo-app-stg prompt_gc; echo $GC_PROMPT'→<GCP:mo-app-stg>bash -c 'source .functions; prompt_gc; echo "[$GC_PROMPT]"'(unset) →[]bash -c 'source .functions; export CLOUDSDK_CORE_PROJECT=mo-app-stg; gps --list | grep -E "^\\* "'→* mo-app-stgbash -c 'export CLOUDSDK_CORE_PROJECT=mo-app-stg; gcloud config get-value project'→mo-app-stg(env var overrides active config)CLOUDSDK_CORE_PROJECT=mo-app-stg bq show --format=json | head -1→ returns themo-app-stgproject record (confirmsbqhonors the env var)CLOUDSDK_CORE_PROJECT=mo-app-stg gsutil ls→ listsmo-app-stgbuckets (confirmsgsutilhonors the env var; AIRULES claim is empirically validated for this environment)gcloudfailure (gcloud() { return 1; }) → bothgps --listandgps mo-appprintgps: failed to list GCP projectsto stderr and exit 1gps, pick a project via fzf, confirm prompt updates andgcloud config get-value projectreflects the choicegps --clearclears the env var and prompt indicator without affecting the first tab