diff --git a/modules/aws/functions/_aws_switch_profile b/modules/aws/functions/_aws_switch_profile new file mode 100644 index 0000000..434f5b3 --- /dev/null +++ b/modules/aws/functions/_aws_switch_profile @@ -0,0 +1,13 @@ +#compdef aws_switch_profile +#autoload + +if [[ ! -f ~/.aws/credentials ]]; then + return 1 +fi + +local profiles +profiles=$(grep -E "^\[.+\]" ~/.aws/credentials | tr -d '[' | tr -d ']' ) + +_arguments "1:toggle:(( +$profiles +))" && return 0 diff --git a/modules/aws/init.zsh b/modules/aws/init.zsh index 5271b75..6bde1a9 100644 --- a/modules/aws/init.zsh +++ b/modules/aws/init.zsh @@ -127,3 +127,12 @@ function aws_cf { function ssh_aws_any { aws_ssm_session_any $1 ssh } + +function aws_switch_profile { + echo "Activating profile $1..." + export AWS_PROFILE=$1 + + if [[ -f ~/.aws/credentials ]]; then #&& (( ! ${+AWS_DEFAULT_REGION} )) + export AWS_DEFAULT_REGION=$(aws configure get region) + fi +}