If you are using awsume
for AWS role switching then it's handy to be able to see how long you have left before the role expires.
Put the following in your .zshrc
so it can be available at any point:
alias timeremaining='_timeremaining'
_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
}
To add a segment you need to edit your p10k.zsh
and add the following:
##################################[ awsenv: current aws env ]#################################
# Gets the current AWS environment (if set)
function prompt_awsenv() {
if (( ${+AWSUME_PROFILE} )); then
local time_remain=$(_timeremaining $AWSUME_EXPIRATION)
if [[ $time_remain == "00:00" ]]; then
local state=EXPIRED
#prompt_segment red white "$AWSUME_PROFILE $time_remain"
else
local state=VALID
#prompt_segment white black "$AWSUME_PROFILE $time_remain"
fi
p10k segment -s $state -b 2 -f 8 -t "${AWSUME_PROFILE} ${time_remain}"
fi
}
# typeset -g POWERLEVEL9K_AWSENV_FOREGROUND=0
# typeset -g POWERLEVEL9K_AWSENV_BACKGROUND=7
typeset -g POWERLEVEL9K_AWSENV_EXPIRED_FOREGROUND=white
typeset -g POWERLEVEL9K_AWSENV_EXPIRED_BACKGROUND=red
# Custom icon.
# typeset -g POWERLEVEL9K_AWSENV_VISUAL_IDENTIFIER_EXPANSION='⭐'
# Custom prefix.
# typeset -g POWERLEVEL9K_AWSENV_PREFIX='env '
Finally add currnodeenv
to typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
in order to get it to show on the right prompt or wherever you wish for it to appear