Last active
October 3, 2021 15:18
-
-
Save thiagosanches/0871a87d3c7154c2258d2c2f531b8fe5 to your computer and use it in GitHub Desktop.
aws-getter.sh
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 | |
# Run with source: | |
# source ./aws-getter.sh and you should be good - it will set your environment variable. | |
TEMP_FILE="/tmp/all-accounts.txt" | |
rm -rf $TEMP_FILE | |
cat ~/.aws/credentials | grep -E "\[.*?\]" | tr "[" " " | tr "]" " " | sort | uniq > $TEMP_FILE | |
INDEX=1 | |
OPTIONS='' | |
ARRAY=() | |
while IFS=$'\n' read -r i | |
do | |
OPTIONS=$(echo "$OPTIONS $INDEX $i off ") | |
INDEX=$(echo $INDEX + 1 | bc) | |
ARRAY+=($i) | |
done < $TEMP_FILE | |
echo $OPTIONS | |
OUTPUT=$(dialog --radiolist "Choose the AWS profile:" 35 75 50 $OPTIONS --output-fd 1) | |
OUTPUT=$(echo $OUTPUT - 1 | bc) | |
export AWS_PROFILE=$(echo ${ARRAY[$OUTPUT]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment