-
-
Save clavery-chef/9af04d6c4a964873ddbe06a4679221d9 to your computer and use it in GitHub Desktop.
okta_aws plugin for oh-my-zsh
This file contains 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
# 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