Last active
February 6, 2019 17:05
-
-
Save uZer/dfd2240bfe1b48ba001560fbe964050b to your computer and use it in GitHub Desktop.
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
awsprofile() { | |
profile=${AWS_CREDENTIAL_FILE:-${HOME}/.aws/credentials} | |
list=$(grep '\[' ${profile} | tr -d '[' | tr -d ']' | xargs) | |
if [ ! $# -eq 1 ]; then | |
echo "Available profiles:" | |
echo $list | sed 's/ /\n/g' | sed 's/^/* /g' | |
else | |
if ! grep -q "\[$1\]" ${profile}; then | |
echo "Profile ${1} doesn't exist in ${profile}." | |
else | |
export AWS_PROFILE=${1:-default} | |
echo "Switching profile to ${1}..." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment