Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added export of Expiration time to Env #98

Merged
merged 3 commits into from
Apr 9, 2020

Conversation

parkeyparker
Copy link
Contributor

In order to calculate time remaining before expiry of a session this will export an extra environment variable: AWSUME_EXPIRATION. With this the remaining time can be calculated and displayed in the prompt in order to determine whether you need to renew the session.

Example usage within .zshrc:

_timeremaining() {
  secs_future=$(date -j -f "%Y-%m-%dT%H:%M:%S" $1 +%s)
  secs_now=$(date +%s)
  secs_remaining=$(( $secs_future - $secs_now ))
  if [ "$secs_remaining" -lt "0" ]; then
  	echo "00:00"
  elif [ "$secs_remaining" -lt "3600" ]; then
  	gdate -d@$secs_remaining -u +%M:%S
  else
    gdate -d@$secs_remaining -u +%H:%M:%S
  fi
}

alias awsenvtimeremain='_awsenvtimeremain'
_awsenvtimeremain() {
  if [[ -v AWSUME_PROFILE ]]; then
    time_remain=$(_timeremaining $AWSUME_EXPIRATION)
    echo "$time_remain"
  fi
}

Then just call awsenvtimeremain() in your prompt definition.

Screenshot 2020-04-08 at 13 13 47

In order to calculate time remaining before expiry of a session this will export an extra environment variable: AWSUME_EXPIRATION. With this the remaining time can be calculated and displayed in the prompt in order to determine whether you need to renew the session.
@mbarneyjr
Copy link
Member

Hi @parkeyparker,

This looks great! Thanks for the PR! We'll take a look 😄

@mbarneyjr mbarneyjr merged commit 6e83f7b into trek10inc:master Apr 9, 2020
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.

None yet

2 participants