Skip to content

Extract aps/gps logic into bin/ scripts#232

Draft
ikuwow wants to merge 1 commit into
mainfrom
aps-gps-to-bin
Draft

Extract aps/gps logic into bin/ scripts#232
ikuwow wants to merge 1 commit into
mainfrom
aps-gps-to-bin

Conversation

@ikuwow

@ikuwow ikuwow commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Why

The aps / gps functions in .functions have grown large. Moving the bulk of the logic into standalone bin/ 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 to bin/ is impossible. Instead, the heavy lifting lives in bin/aps and bin/gps, and .functions keeps only thin wrappers responsible for the export.

  • Both commands already persist their selected state on disk (~/.aws/current_profile, gcloud active_config), so the wrapper just re-reads that file after the script returns.
  • The wrapper calls command aps "$@" to bypass the function and reach the script on $PATH.

The original if [ ! "$(command -v aps)" ] guards in .functions are removed: once bin/aps is on $PATH they would be permanently false and the wrapper would never be defined.

deploy.sh already auto-symlinks any 0755 file under bin/ via find, so no changes are needed there.

Verification

  • shellcheck bin/aps bin/gps clean
  • bash -c 'PATH=$HOME/bin:$PATH; source ~/.functions; aps --list; echo AWS_PROFILE=$AWS_PROFILE' confirmed AWS_PROFILE is set correctly via the wrapper
  • Same flow for gps --list confirmed GC_ACTIVE_CONFIG is set
  • aps --clear clears AWS_PROFILE to empty string and removes ~/.aws/current_profile
  • aps --help / gps --help print help and exit (no env change beyond idempotent re-export — see Notes)
  • Interactive fzf selection paths (aps <query>, aps, gps <query>, gps) verified in a real shell
  • SSO session-expired case (aws sts get-caller-identity Account ID not 14 digits) triggers aws sso login

Notes

  • The SSO login check inside bin/aps runs as AWS_PROFILE=$profile aws ... since export does not propagate to the parent (and the script does not need to set the env for itself).
  • For read-only commands (--help, --list), the wrapper still re-exports AWS_PROFILE from the persisted file unconditionally. This is idempotent against the persisted state so there is no functional issue. Use aps --clear to actually drop the export.

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant