Last active
October 22, 2024 08:29
-
-
Save abdallah/fc3440ed8155aff4bb32127c0a8812f0 to your computer and use it in GitHub Desktop.
Zsh hook to check AWS account on profile change
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
| # 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