From 4166f55fd401bc86e1d2dc7a7051774f550bfc8e Mon Sep 17 00:00:00 2001 From: Andrea Mistrali Date: Wed, 27 Oct 2021 10:28:45 +0200 Subject: [PATCH] Another step in awslogin --- zsh.d/zshfunctions/awslogin | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/zsh.d/zshfunctions/awslogin b/zsh.d/zshfunctions/awslogin index d5f256e..ee0795e 100644 --- a/zsh.d/zshfunctions/awslogin +++ b/zsh.d/zshfunctions/awslogin @@ -1,8 +1,17 @@ -if [ $1 ]; then - export AWS_DEFAULT_PROFILE=$1 - export AWS_PROFILE=$1 - export AWS_EB_PROFILE=$1 - return +profile=$1 + +if [ $profile ]; then + match=$(grep $profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/') + if [ $match ]; then + echo "Activating $match" + export AWS_DEFAULT_PROFILE=$match + export AWS_PROFILE=$match + export AWS_EB_PROFILE=$match + return + else + echo "No match for $profile" + return + fi elif [ $AWS_PROFILE ]; then unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE echo AWS profile cleared.