diff --git a/zsh.d/zshfunctions/awslogin b/zsh.d/zshfunctions/awslogin deleted file mode 100644 index ee0795e..0000000 --- a/zsh.d/zshfunctions/awslogin +++ /dev/null @@ -1,22 +0,0 @@ -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. - return -fi - -echo "Available profiles" -grep profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/' diff --git a/zsh.d/zshfunctions/awslogin.zwc b/zsh.d/zshfunctions/awslogin.zwc deleted file mode 100644 index 70a418a..0000000 Binary files a/zsh.d/zshfunctions/awslogin.zwc and /dev/null differ diff --git a/zsh.d/zshfunctions/awsprofile b/zsh.d/zshfunctions/awsprofile new file mode 100644 index 0000000..cc118cc --- /dev/null +++ b/zsh.d/zshfunctions/awsprofile @@ -0,0 +1,30 @@ +profile=$1 + +if [ $profile ]; then # We got a profile pattern, look for a match + match=$(grep -E "\[profile .*$profile.*" ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/') + match_no=$(echo $match|wc -l) + if [ $match_no -gt 1 ]; then # more than one match + echo "Multiple matches:" + echo $match + return + fi + + if [ $match ]; then # Single match, setting profile + 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 # no profile passed, clean up current one, logout + unset AWS_DEFAULT_PROFILE AWS_PROFILE AWS_EB_PROFILE + echo profile cleared. + return +fi + +echo "Available profiles" +grep profile ~/.aws/config | sed -E 's/\[profile (.+)\]/\1/' +# vim: set ts=2 sw=2 tw=0 ft=sh : diff --git a/zsh.d/zshfunctions/awsprofile.zwc b/zsh.d/zshfunctions/awsprofile.zwc new file mode 100644 index 0000000..3bf0493 Binary files /dev/null and b/zsh.d/zshfunctions/awsprofile.zwc differ