Skip to content

Instantly share code, notes, and snippets.

@abdallah
Last active October 22, 2024 08:29
Show Gist options
  • Select an option

  • Save abdallah/fc3440ed8155aff4bb32127c0a8812f0 to your computer and use it in GitHub Desktop.

Select an option

Save abdallah/fc3440ed8155aff4bb32127c0a8812f0 to your computer and use it in GitHub Desktop.
Zsh hook to check AWS account on profile change
# Add to ~/.zshrc
# https://github.com/rothgar/mastering-zsh/blob/master/docs/config/hooks.md
# precmd is executed before your prompt is displayed and is often used to set values in your $PROMPT. preexec is executed between when you press enter on a command prompt but before the command is executed
precmd() {
if [[ $CURRENT_PROFILE != "$AWS_PROFILE" ]]; then
echo changed, checking sts;
export CURRENT_PROFILE=$AWS_PROFILE;
if ! aws sts get-caller-identity; then
aws sso login
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment