From 3f9582b6fb7c3007d8b374349b5e53b95ab25e05 Mon Sep 17 00:00:00 2001 From: Sebastian Noe Date: Tue, 9 Apr 2024 11:33:08 +0200 Subject: [PATCH 1/3] support aws cli cached credentials --- functions/fish_prompt.fish | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 21058ea8..35a4def6 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -656,17 +656,27 @@ end # Cloud Tools # ============================== -function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile' - [ "$theme_display_aws_vault_profile" = 'yes' ] +function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS \(Vault\) profile' + [ "$theme_display_aws_vault_profile" = 'yes' -o "$theme_display_aws_profile" = 'yes' ] or return - [ -n "$AWS_VAULT" -a -n "$AWS_SESSION_EXPIRATION" ] + set -l AWS_SSO_CLI_CACHE (grep -Ril "startUrl" ~/.aws/sso/cache) + + [ -n "$AWS_SESSION_EXPIRATION" -a \( -n "$AWS_VAULT" -o -n "$AWS_PROFILE" \) -o -n "$AWS_SSO_CLI_CACHE" ] or return - set -l profile $AWS_VAULT + [ -n "$AWS_SSO_CLI_CACHE" ] + and set -l expiry_date (cat $AWS_SSO_CLI_CACHE | jq -r .expiresAt ) + and set -l profile "AWS SSO CLI Profile" + [ -n "$AWS_VAULT" ] + and set -l profile $AWS_VAULT + [ -n "$AWS_PROFILE" ] + and set -l profile $AWS_PROFILE set -l now (date --utc +%s) - set -l expiry (date -d "$AWS_SESSION_EXPIRATION" +%s) + [ -n "$AWS_PROFILE" ] + and set -l expiry (date -d "$AWS_SESSION_EXPIRATION" +%s) + or set -l expiry (date -d "$expiry_date" +%s) set -l diff_mins (math "floor(( $expiry - $now ) / 60)") set -l diff_time $diff_mins"m" From a653bce8ed3bdaab95f84e9a04ecdd781960c30d Mon Sep 17 00:00:00 2001 From: Sebastian Noe Date: Tue, 9 Apr 2024 11:33:19 +0200 Subject: [PATCH 2/3] venv display --- functions/fish_prompt.fish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 35a4def6..43d21ee6 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -1212,3 +1212,6 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_finish_segments end +if set -q VIRTUAL_ENV + echo -n -s (set_color -b blue white) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal) " " +end From 0e37ec3555f923dead89a8eb1a6be45633eb4ec6 Mon Sep 17 00:00:00 2001 From: Sebastian Noe Date: Mon, 24 Jun 2024 10:04:43 +0200 Subject: [PATCH 3/3] handle multiple files and do not show expired sessions --- functions/fish_prompt.fish | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 43d21ee6..8f40e2e4 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -660,20 +660,32 @@ function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS \(Vault\) profile [ "$theme_display_aws_vault_profile" = 'yes' -o "$theme_display_aws_profile" = 'yes' ] or return - set -l AWS_SSO_CLI_CACHE (grep -Ril "startUrl" ~/.aws/sso/cache) + set -l AWS_SSO_CLI_CACHE (grep -Ril --exclude "aws*" "startUrl" ~/.aws/sso/cache) [ -n "$AWS_SESSION_EXPIRATION" -a \( -n "$AWS_VAULT" -o -n "$AWS_PROFILE" \) -o -n "$AWS_SSO_CLI_CACHE" ] or return + # Filter out files that contain the "scopes" key + for file in $AWS_SSO_CLI_CACHE + cat $file | jq 'has("scopes")' | grep -q true + and set AWS_SSO_CLI_CACHE (echo $AWS_SSO_CLI_CACHE | grep -v $file) + end + [ -n "$AWS_SSO_CLI_CACHE" ] - and set -l expiry_date (cat $AWS_SSO_CLI_CACHE | jq -r .expiresAt ) - and set -l profile "AWS SSO CLI Profile" + and set -l expiry_date (cat $AWS_SSO_CLI_CACHE | jq -r .expiresAt) + and set -l expiry (date -d "$expiry_date" +%s) + and set -l now (date --utc +%s) + + [ $now -gt $expiry ] + and return + + set -l profile "AWS SSO CLI Profile" + [ -n "$AWS_VAULT" ] and set -l profile $AWS_VAULT [ -n "$AWS_PROFILE" ] and set -l profile $AWS_PROFILE - set -l now (date --utc +%s) [ -n "$AWS_PROFILE" ] and set -l expiry (date -d "$AWS_SESSION_EXPIRATION" +%s) or set -l expiry (date -d "$expiry_date" +%s) @@ -695,6 +707,8 @@ function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS \(Vault\) profile end + + # ============================== # User / hostname info segments # ==============================