Skip to content

Instantly share code, notes, and snippets.

@scooter-dangle
Created January 23, 2020 04:28
Show Gist options
  • Save scooter-dangle/a1fe5d9d5cb999c3d728cde78c7bcec8 to your computer and use it in GitHub Desktop.
Save scooter-dangle/a1fe5d9d5cb999c3d728cde78c7bcec8 to your computer and use it in GitHub Desktop.
Lightweight AWS env loader for fish
# AWS_ENV var is meant to be combined with the following
# function in the shell prompt
function __fish_aws_creds_prompt
if set --query AWS_ENV
if string match --ignore-case --quiet --regex 'pro?d' "$AWS_ENV"
set aws_name_color brred
else
set aws_name_color bryellow
end
set_color brwhite
printf "["
set_color $aws_name_color
printf "aws:$AWS_ENV"
set_color brwhite
printf "]"
set_color normal
end
end
function aws_env
for arg in $argv
set env_args $env_args AWS_ENV=(basename -s .gpg $arg)
if string match --quiet --regex '\.gpg$' "$arg"
set env_args $env_args (gpg --decrypt ~/.aws/profiles/"$arg")
else
set env_args $env_args (cat ~/.aws/profiles/"$arg")
end
end
env $env_args fish
end
complete --command aws_env --arguments "(ls ~/.aws/profiles/)" --authoritative --exclusive
# Example unencrypted contents of ~/.aws/profiles/research-east.gpg:
#
# AWS_ACCESS_KEY_ID=123xyz
# AWS_SECRET_ACCESS_KEY=111222
# AWS_DEFAULT_REGION=us-east-1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment