Skip to content

Instantly share code, notes, and snippets.

@rotated8
Last active July 30, 2019 16:26
Show Gist options
  • Save rotated8/12a109b640cd559cbfba72e8ed49bbd3 to your computer and use it in GitHub Desktop.
Save rotated8/12a109b640cd559cbfba72e8ed49bbd3 to your computer and use it in GitHub Desktop.
TKI function for Bash prompt
# If AWS credentials have been updated in the last 12 hours, TKI is probably ok.
CHECK_TKI=false # Change to 'true' to enable the check.
function warn_tki {
if [[ -e "$HOME/.aws/credentials" && $CHECK_TKI == 'true' ]]; then
date_format="%Y%m%d%H%M%S" # Reduces time to a comparable number, not epoch dependant.
mod_time=$(date --reference="$HOME/.aws/credentials") # Time AWS creds were modified.
expire_time=$(date --date="$mod_time + 43200 seconds" +"$date_format") # Add 12 hours.
if [[ "$expire_time" -ge "$(date +$date_format)" ]]; then
echo -e '\033[0;32mTKI:✓ ' # Green
else
echo -e '\033[0;31mTKI:× ' # Red
fi
fi
}
# Add to the beginning of your prompt by uncommenting the next line.
#PS1="\$(warn_tki)\$PS1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment