Last active
May 13, 2021 10:09
-
-
Save dotarr/f3053ce91e1990d5be0b161b21285e1e to your computer and use it in GitHub Desktop.
Interactive AWS profile selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CONFIG_FILE="${HOME}/.aws/config" | |
function awsprofile() { | |
if [ -z ${AWS_PROFILE+x} ]; then msg="AWS_PROFILE is unset"; else msg="Current AWS_PROFILE=${AWS_PROFILE}"; fi | |
echo -e "\n${msg}" | |
echo -e "Available profiles:\n" | |
PS3=$'\n'"Use number to select, 'u' to unset or 'q' to quit: " | |
select profile in $(awk '/^\[/ { gsub("]", ""); print $2 }' <${CONFIG_FILE}); do | |
if [[ "${REPLY}" == q ]]; then break; fi | |
if [[ "${REPLY}" == u ]]; then | |
unset AWS_PROFILE | |
echo "AWS_PROFILE unset" | |
break | |
fi | |
if [[ "${profile}" == "" ]]; then | |
echo "'${REPLY}' is not a valid number" | |
continue | |
fi | |
export AWS_PROFILE=${profile} | |
echo "AWS_PROFILE set to ${AWS_PROFILE}" | |
break | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment