Extract aps/gps logic into bin/ scripts#232
Draft
ikuwow wants to merge 1 commit into
Draft
Conversation
Move the bulk of the aps and gps switchers (help text, --list/--clear branches, fzf selection, SSO login check) into bin/aps and bin/gps, keeping only thin wrappers in .functions that handle the parent-shell env export (AWS_PROFILE, GC_ACTIVE_CONFIG) — which a subprocess script cannot do itself. Co-authored-by: Claude Opus 4.7 (1M context) <[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
The
aps/gpsfunctions in.functionshave grown large. Moving the bulk of the logic into standalonebin/scripts makes them easier to shellcheck and edit on their own.Design
Both commands need to export shell environment variables (
AWS_PROFILE,GC_ACTIVE_CONFIG) into the parent shell, which a subprocess script cannot do. So a full move tobin/is impossible. Instead, the heavy lifting lives inbin/apsandbin/gps, and.functionskeeps only thin wrappers responsible for the export.~/.aws/current_profile, gcloudactive_config), so the wrapper just re-reads that file after the script returns.command aps "$@"to bypass the function and reach the script on$PATH.The original
if [ ! "$(command -v aps)" ]guards in.functionsare removed: oncebin/apsis on$PATHthey would be permanently false and the wrapper would never be defined.deploy.shalready auto-symlinks any 0755 file underbin/viafind, so no changes are needed there.Verification
shellcheck bin/aps bin/gpscleanbash -c 'PATH=$HOME/bin:$PATH; source ~/.functions; aps --list; echo AWS_PROFILE=$AWS_PROFILE'confirmedAWS_PROFILEis set correctly via the wrappergps --listconfirmedGC_ACTIVE_CONFIGis setaps --clearclearsAWS_PROFILEto empty string and removes~/.aws/current_profileaps --help/gps --helpprint help and exit (no env change beyond idempotent re-export — see Notes)aps <query>,aps,gps <query>,gps) verified in a real shellaws sts get-caller-identityAccount ID not 14 digits) triggersaws sso loginNotes
bin/apsruns asAWS_PROFILE=$profile aws ...sinceexportdoes not propagate to the parent (and the script does not need to set the env for itself).--help,--list), the wrapper still re-exportsAWS_PROFILEfrom the persisted file unconditionally. This is idempotent against the persisted state so there is no functional issue. Useaps --clearto actually drop the export.