From f2344481901b2cea0595dc31c44027fa3e9ffc03 Mon Sep 17 00:00:00 2001 From: Rogier Date: Sun, 25 Apr 2021 23:13:08 +0200 Subject: [PATCH 1/3] add awsume support --- functions/fish_prompt.fish | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 02bfe97..7c32926 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -31,6 +31,7 @@ # set -g theme_display_k8s_context yes # set -g theme_display_k8s_namespace no # set -g theme_display_aws_vault_profile yes +# set -g theme_display_awsume_profile yes # set -g theme_display_hg yes # set -g theme_display_virtualenv no # set -g theme_display_nix no @@ -682,6 +683,38 @@ function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile' echo -ns $segment ' ' end +function __bobthefish_prompt_awsume_profile -S -d 'Show awsume profile' + [ "$theme_display_awsume_profile" = 'yes' ] + or return + + [ -n "$AWSUME_PROFILE" -a -n "$AWSUME_EXPIRATION" ] + or return + + if test (uname) = Darwin + set now (gdate --utc +%s) + set expiry (gdate -d "$AWSUME_EXPIRATION" +%s) + else + set now (date --utc +%s) + set expiry (date -d "$AWSUME_EXPIRATION" +%s) + end + set -l profile $AWSUME_PROFILE + + 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 @@ -1134,6 +1167,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' # Cloud Tools __bobthefish_prompt_aws_vault_profile + __bobthefish_prompt_awsume_profile # Virtual environments __bobthefish_prompt_nix From 703674353d403f0dda2e13e288e18fb7c558add7 Mon Sep 17 00:00:00 2001 From: Rogier Date: Sun, 25 Apr 2021 23:18:14 +0200 Subject: [PATCH 2/3] add check for macos in aws-vault use gdate instead of date due to difference in syntax --- functions/fish_prompt.fish | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/functions/fish_prompt.fish b/functions/fish_prompt.fish index 7c32926..478b400 100644 --- a/functions/fish_prompt.fish +++ b/functions/fish_prompt.fish @@ -662,10 +662,15 @@ function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile' [ -n "$AWS_VAULT" -a -n "$AWS_SESSION_EXPIRATION" ] or return + if test (uname) = Darwin + set now (gdate --utc +%s) + set expiry (gdate -d "$AWS_SESSION_EXPIRATION" +%s) + else + set now (date --utc +%s) + set expiry (date -d "$AWS_SESSION_EXPIRATION" +%s) + end + set -l profile $AWS_VAULT - - 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" From 6c40efa01d535ca7930011ebc0d01bcec178d186 Mon Sep 17 00:00:00 2001 From: Rogier Date: Sun, 25 Apr 2021 23:22:54 +0200 Subject: [PATCH 3/3] update readme, add awsume details, req. coreutils --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 85a6550..d1ed3f9 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,10 @@ You will need a [Powerline-patched font][btf-patching] for this to work, unless This theme is based loosely on [agnoster][btf-agnoster]. +For MacOS install coreutils to get gdate as date has a different syntax. This is required for aws-vault and awsume support in the bobthefish prompt on MacOS. + brew intall coreutils + ### Features * A helpful, but not too distracting, greeting. @@ -130,6 +133,7 @@ set -g theme_newline_prompt '$ ' - `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`). - `theme_display_k8s_namespace`. This feature is disabled by default. Use `yes` to show the current kubernetes namespace. - `theme_display_aws_vault_profile`. This feature is disabled by default. Use `yes` to show the currently executing [AWS Vault](https://github.com/99designs/aws-vault) profile. +- `theme_display_awsume_profile`. This feature is disabled by default. Use `yes` to show the currently executing awsume profile. - `theme_display_user`. If set to `yes`, display username always, if set to `ssh`, only when an SSH-Session is detected, if set to no, never. - `theme_display_hostname`. Same behaviour as `theme_display_user`. - `theme_display_sudo_user`. If set to `yes`, displays the sudo-username in a root shell. For example, when calling `sudo -s` and having this option set to `yes`, the username of the user, who called `sudo -s`, will be displayed.