diff --git a/modules/aws/functions/aws-info b/modules/aws/functions/aws-info index 1035548..c021964 100644 --- a/modules/aws/functions/aws-info +++ b/modules/aws/functions/aws-info @@ -7,19 +7,26 @@ local profile_format local profile_formatted +local aws_prompt +local aws_region_prompt unset aws_info typeset -gA aws_info +if (( ${+AWS_SECRET_ACCESS_KEY} )); then + aws_prompt='ACCESS_KEY' +elif (( ${+AWS_PROFILE} )); then + aws_prompt=$AWS_PROFILE -if (( ${+AWS_PROFILE} )); then - if (( ${+AWS_DEFAULT_REGION} )) && [[ ${_aws_region} = "true" ]]; then - AWS_REGION=$(cut -d "-" -f 1 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 2 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 3 <<<$AWS_DEFAULT_REGION | cut -b 1) - AWS_REGION_PROMPT=" $AWS_REGION" - fi + if (( ${+AWS_DEFAULT_REGION} )) && [[ ${_aws_region} = "true" ]]; then + AWS_REGION=$(cut -d "-" -f 1 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 2 <<<$AWS_DEFAULT_REGION | cut -b 1)$(cut -d "-" -f 3 <<<$AWS_DEFAULT_REGION | cut -b 1) + aws_region_prompt=" $AWS_REGION" + fi +fi +if (( ${+AWS_SECRET_ACCESS_KEY} )) || (( ${+AWS_DEFAULT_REGION} )); then zstyle -s ':prezto:module:aws:info:profile' format 'profile_format' - zformat -f profile_formatted "$profile_format" "v:${AWS_PROFILE:t}${AWS_REGION_PROMPT}" + zformat -f profile_formatted "$profile_format" "v:${aws_prompt:t}${aws_region_prompt}" aws_info[profile]="$profile_formatted" fi diff --git a/modules/aws/init.zsh b/modules/aws/init.zsh index 1b50b54..d23e412 100644 --- a/modules/aws/init.zsh +++ b/modules/aws/init.zsh @@ -154,6 +154,7 @@ function aws_switch_profile { fi echo "Activating profile $1..." + unset -m "AWS_*" export AWS_PROFILE=$1 if [[ -f ~/.aws/credentials ]]; then #&& (( ! ${+AWS_DEFAULT_REGION} )) region=$(aws configure get region) @@ -167,6 +168,5 @@ function aws_switch_profile { function aws_deactivate_profile { echo "Deactivating aws profile..." - unset AWS_PROFILE - unset AWS_DEFAULT_REGION + unset -m "AWS_*" }