diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 1ec90fd..8197b80 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -684,6 +684,33 @@ function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile' echo -ns $segment ' ' end +function __bobthefish_prompt_aws_profile -S -d 'Show current AWS profile' + [ "$theme_display_aws_profile" = 'yes' ] + or return + + [ -n "$AWS_PROFILE" -a -n "$AWS_SESSION_EXPIRATION" ] + or return + + set -l profile $AWS_PROFILE + + set -l now (date --utc +%s) + set -l expiry (date -d "$AWS_SESSION_EXPIRATION" +%s) + set -l diff_mins (math "floor(( $expiry - $now ) / 60)") + + set -l diff_time $diff_mins"m" + [ $diff_mins -le 0 ] + and set -l diff_time '0m' + [ $diff_mins -ge 60 ] + and set -l diff_time (math "floor($diff_mins / 60)")"h"(math "$diff_mins % 60")"m" + + set -l segment $profile ' (' $diff_time ')' + set -l status_color $color_aws_vault + [ $diff_mins -le 0 ] + and set -l status_color $color_aws_vault_expired + + __bobthefish_start_segment $status_color + echo -ns $segment ' ' +end # ============================== # User / hostname info segments @@ -1169,6 +1196,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' # Cloud Tools __bobthefish_prompt_aws_vault_profile + __bobthefish_prompt_aws_profile # Virtual environments __bobthefish_prompt_nix