Skip to content

Instantly share code, notes, and snippets.

@clavery-chef
Forked from irvingpop/okta-aws.plugin.zsh
Last active August 10, 2020 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clavery-chef/9af04d6c4a964873ddbe06a4679221d9 to your computer and use it in GitHub Desktop.
Save clavery-chef/9af04d6c4a964873ddbe06a4679221d9 to your computer and use it in GitHub Desktop.
okta_aws plugin for oh-my-zsh
# shellcheck disable=SC2148
# shellcheck disable=SC2034
# okta-aws plugin for oh-my-zsh
# for use with the bullet-train oh-my-zsh theme: https://github.com/caiogondim/bullet-train.zsh
# (although this could be easily changed)
# Irving Popovetsky <irving@chef.io>
# default profile is used if you don't set one using AWS_PROFILE, which is recommended
OKTA_AWS_DEFAULT_PROFILE="chef-support"
function okta_aws_init () {
if [[ -n "${AWS_PROFILE}" ]]; then
okta_aws "${AWS_PROFILE}" || return
else
okta_aws "${OKTA_AWS_DEFAULT_PROFILE}" || return
fi
okta_session
}
function okta_session () {
date +%s > ~/.okta_session_time
}
function okta_session_prompt () {
local current_time session_time time_since
if [ -f ~/.okta_session_time ]; then
session_time="$(cat ~/.okta_session_time)"
else
session_time=0
fi
current_time="$(date +%s)"
time_since=$((current_time - session_time))
if [ "${time_since}" -gt 3600 ]; then
# change the aws part of the prompt to green when its being updated
BULLETTRAIN_AWS_BG=green
okta_aws_init
else
# change it back to yellow, the default
BULLETTRAIN_AWS_BG=yellow
fi
}
# neat trick to not clobber zle-line-init from: https://github.com/robbyrussell/oh-my-zsh/blob/d2dfa69419845daebcfd20fed3253ae06faa2876/plugins/git-auto-fetch/git-auto-fetch.plugin.zsh
eval "override-okta-aws-$(declare -f zle-line-init)"
function zle-line-init () {
override-okta-aws-zle-line-init
okta_session_prompt
}
zle -N zle-line-init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment