-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzsh-saml2aws-auto.plugin.zsh
More file actions
executable file
·41 lines (34 loc) · 1.15 KB
/
zsh-saml2aws-auto.plugin.zsh
File metadata and controls
executable file
·41 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
alias s2a="saml2aws-auto"
aws_profile() {
if [[ "$AWS_PROFILE" != "" ]];
then
# We got a profile
local aws_icon='\uf52c'
local result=$(grep "name: $AWS_PROFILE$" ~/.saml2aws-auto.yml)
local time_diff=""
if [[ ${result} != "" ]]; then
# Profile is configured
local current_timestamp=$(date +%s)
local valid_until=$(grep -A2 "$AWS_PROFILE" ~/.saml2aws-auto.yml \
| awk '{ if($1 == "valid_until:") { print $2 } }' \
| tr -d '"')
local valid_until_timestamp=$(TZ=GMT+0:00 date -j -f "%Y-%m-%dT%H:%M:%S+00:00" ${valid_until} +%s)
if [[ $current_timestamp -le $valid_until_timestamp ]]; then
# Token is still valid
time_diff="~$(( ($valid_until_timestamp - $current_timestamp) / 60 ))min"
FGC='%F{green}'
COLOR='%K{green}%F{black}'
else
# Token expired
FGC='%F{yellow}'
COLOR='%K{yellow}%F{black}'
fi
else
# Profile is not configured
FGC='%F{red}'
COLOR='%K{red}%F{black}'
fi
echo "%{$FGC%}\uE0B2%{$reset_color%}%{$COLOR%} ${aws_icon} $AWS_PROFILE ${time_diff} %{$reset_color%}"
fi
}
RPROMPT='$(aws_profile)'