From df777cd7e2cfd315aa363052f78c7500fb5824c0 Mon Sep 17 00:00:00 2001 From: Darren Kidd Date: Tue, 8 Sep 2020 15:06:39 +1200 Subject: [PATCH] Create new segment for AWS Vault profile * Tracks the session expiration information and adds this to the segment as well (if available - which it should be). * Using basic blue/white colours at the moment. * Added doco including link to AWS Vault repo. --- README.md | 1 + fish_prompt.fish | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/README.md b/README.md index 381fb89..a99cfb6 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ set -g theme_newline_prompt '$ ' - `theme_display_vi`. By default the vi mode indicator will be shown if vi or hybrid key bindings are enabled. Use `no` to hide the indicator, or `yes` to show the indicator. - `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_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. diff --git a/fish_prompt.fish b/fish_prompt.fish index 6121652..318e9d0 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -29,6 +29,7 @@ # set -g theme_display_docker_machine no # 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_hg yes # set -g theme_display_virtualenv no # set -g theme_display_nix no @@ -644,6 +645,32 @@ function __bobthefish_prompt_k8s_context -S -d 'Show current Kubernetes context' end +# ============================== +# Cloud Tools +# ============================== + +function __bobthefish_prompt_aws_vault_profile -S -d 'Show AWS Vault profile' + [ "$theme_display_aws_vault_profile" = 'yes' ] + or return + + [ -n "$AWS_VAULT" -a -n "$AWS_SESSION_EXPIRATION" ] + or return + + 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)") + [ "$diff_mins" -lt 0 ] + and set -l diff_mins 0 + + set -l segment $profile " (" $diff_mins "m)" + + __bobthefish_start_segment blue white --bold + echo -ns $segment " " +end + + # ============================== # User / hostname info segments # ============================== @@ -1076,6 +1103,9 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome' __bobthefish_prompt_docker __bobthefish_prompt_k8s_context + # Cloud Tools + __bobthefish_prompt_aws_vault_profile + # Virtual environments __bobthefish_prompt_nix __bobthefish_prompt_desk