Skip to content

Commit

Permalink
Support AWS_PROFILE for AWS integration
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandocarletti committed Sep 27, 2021
1 parent 626bd39 commit b69c8b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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_profile`. This feature is disabled by default. Use `yes` to show the currently [AWS](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) profile.
- `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`.
Expand Down
30 changes: 15 additions & 15 deletions functions/__bobthefish_colors.fish
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_aws_vault blue $colorfg --bold
set -x color_aws blue $colorfg --bold
set -x color_aws_vault_expired blue red --bold
set -x color_username white black --bold
set -x color_hostname white black
Expand Down Expand Up @@ -63,7 +63,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_aws_vault blue $colorfg --bold
set -x color_aws blue $colorfg --bold
set -x color_aws_vault_expired blue red --bold
set -x color_username black white --bold
set -x color_hostname black white
Expand Down Expand Up @@ -98,7 +98,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_aws_vault blue $colorfg --bold
set -x color_aws blue $colorfg --bold
set -x color_aws_vault_expired blue red --bold
set -x color_username brgrey white --bold
set -x color_hostname brgrey white
Expand Down Expand Up @@ -133,7 +133,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_aws_vault blue $colorfg --bold
set -x color_aws blue $colorfg --bold
set -x color_aws_vault_expired blue red --bold
set -x color_username grey black --bold
set -x color_hostname grey black
Expand Down Expand Up @@ -174,7 +174,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $blue $green --bold
set -x color_k8s $green $white --bold
set -x color_aws_vault $blue $grey --bold
set -x color_aws $blue $grey --bold
set -x color_aws_vault_expired $blue $red --bold
set -x color_username $grey $blue --bold
set -x color_hostname $grey $blue
Expand Down Expand Up @@ -226,7 +226,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $base0C $colorfg --bold
set -x color_k8s $base06 $colorfg --bold
set -x color_aws_vault $base0D $colorfg --bold
set -x color_aws $base0D $colorfg --bold
set -x color_aws_vault_expired $base0D $base08 --bold
set -x color_username $base02 $base0D --bold
set -x color_hostname $base02 $base0D
Expand Down Expand Up @@ -278,7 +278,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $base0C $colorfg --bold
set -x color_k8s $base0B $colorfg --bold
set -x color_aws_vault $base0D $base0A --bold
set -x color_aws $base0D $base0A --bold
set -x color_aws_vault_expired $base0D $base08 --bold
set -x color_username $base02 $base0D --bold
set -x color_hostname $base02 $base0D
Expand Down Expand Up @@ -330,7 +330,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $violet $colorfg --bold
set -x color_k8s $green $colorfg --bold
set -x color_aws_vault $violet $base3 --bold
set -x color_aws $violet $base3 --bold
set -x color_aws_vault_expired $violet $orange --bold
set -x color_username $base2 $blue --bold
set -x color_hostname $base2 $blue
Expand Down Expand Up @@ -382,7 +382,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $violet $colorfg --bold
set -x color_k8s $green $colorfg --bold
set -x color_aws_vault $violet $base3 --bold
set -x color_aws $violet $base3 --bold
set -x color_aws_vault_expired $violet $orange --bold
set -x color_username $base02 $blue --bold
set -x color_hostname $base02 $blue
Expand Down Expand Up @@ -427,7 +427,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $blue[1] $white --bold
set -x color_k8s $green[1] $colorfg --bold
set -x color_aws_vault $blue[3] $orange[1] --bold
set -x color_aws $blue[3] $orange[1] --bold
set -x color_aws_vault_expired $blue[3] $red[3] --bold
set -x color_username $grey[1] $blue[3] --bold
set -x color_hostname $grey[1] $blue[3]
Expand Down Expand Up @@ -471,7 +471,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $blue[2] $fg[2] --bold
set -x color_k8s $green[2] $fg[2] --bold
set -x color_aws_vault $blue[2] $yellow[1] --bold
set -x color_aws $blue[2] $yellow[1] --bold
set -x color_aws_vault_expired $blue[2] $red[1] --bold
set -x color_username $fg[3] $blue[2] --bold
set -x color_hostname $fg[3] $blue[2]
Expand Down Expand Up @@ -517,7 +517,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $pink $bg --bold
set -x color_k8s $green $fg --bold
set -x color_aws_vault $comment $yellow --bold
set -x color_aws $comment $yellow --bold
set -x color_aws_vault_expired $comment $red --bold
set -x color_username $selection $cyan --bold
set -x color_hostname $selection $cyan
Expand Down Expand Up @@ -569,7 +569,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $base02 $colorfg --bold
set -x color_k8s $base02 $colorfg --bold
set -x color_aws_vault $base0A $base0D --bold
set -x color_aws $base0A $base0D --bold
set -x color_aws_vault_expired $base0A $base0B --bold
set -x color_username $base02 $base0D --bold
set -x color_hostname $base02 $base0D
Expand Down Expand Up @@ -614,7 +614,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe

set -x color_vagrant $blue[1] $white --bold
set -x color_k8s $green[2] $white --bold
set -x color_aws_vault $blue[3] $orange[1] --bold
set -x color_aws $blue[3] $orange[1] --bold
set -x color_aws_vault_expired $blue[3] $red[3] --bold
set -x color_username $grey[1] $blue[3] --bold
set -x color_hostname $grey[1] $blue[3]
Expand Down Expand Up @@ -682,7 +682,7 @@ function __bobthefish_user_color_scheme_deprecated
set -x color_vi_mode_insert $__color_vi_mode_insert
set -x color_vi_mode_visual $__color_vi_mode_visual
set -x color_vagrant $__color_vagrant
set -x color_aws_vault $__color_aws_vault
set -x color_aws $__color_aws_vault
set -x color_aws_vault_expired $__color_aws_vault_expired
set -x color_username $__color_username
set -x color_hostname $__color_hostname
Expand Down
44 changes: 24 additions & 20 deletions functions/fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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_profile yes
# set -g theme_display_aws_vault_profile yes
# set -g theme_display_hg yes
# set -g theme_display_virtualenv no
Expand Down Expand Up @@ -654,32 +655,35 @@ 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_profile -S -d 'Show AWS profile'
[ "$theme_display_aws_profile" = 'yes' -o "$theme_display_aws_vault_profile" = 'yes' ]
or return

[ -n "$AWS_VAULT" -a -n "$AWS_SESSION_EXPIRATION" ]
or return
if set -q "AWS_PROFILE"
__bobthefish_start_segment $color_aws
echo -ns $AWS_PROFILE ' '
end

set -l profile $AWS_VAULT
if set -q "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 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 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
[ $diff_mins -le 0 ]
and set -l status_color $color_aws_vault_expired

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 ' '
__bobthefish_start_segment $color_aws
echo -ns $AWS_VAULT ' '
end
end


Expand Down Expand Up @@ -1133,7 +1137,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
__bobthefish_prompt_k8s_context

# Cloud Tools
__bobthefish_prompt_aws_vault_profile
__bobthefish_prompt_aws_profile

# Virtual environments
__bobthefish_prompt_nix
Expand Down

0 comments on commit b69c8b9

Please sign in to comment.