Skip to content

Instantly share code, notes, and snippets.

@uZer
Last active February 6, 2019 17:05
Show Gist options
  • Save uZer/dfd2240bfe1b48ba001560fbe964050b to your computer and use it in GitHub Desktop.
Save uZer/dfd2240bfe1b48ba001560fbe964050b to your computer and use it in GitHub Desktop.
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