Skip to content

Instantly share code, notes, and snippets.

@thiagosanches
Last active October 3, 2021 15:18
Show Gist options
  • Save thiagosanches/0871a87d3c7154c2258d2c2f531b8fe5 to your computer and use it in GitHub Desktop.
Save thiagosanches/0871a87d3c7154c2258d2c2f531b8fe5 to your computer and use it in GitHub Desktop.
aws-getter.sh
#!/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]})
@thiagosanches
Copy link
Author

image

@thiagosanches
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment