fixed awskeys with all profiles

pull/1070/head
Pablo Diaz 2017-10-27 22:53:41 +02:00
parent 2405fe2c54
commit 9d0da715d3
1 changed files with 9 additions and 7 deletions

View File

@ -42,7 +42,7 @@ function __awskeys_get {
} }
function __awskeys_list { function __awskeys_list {
local credentials_list="$(egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials)" local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials; grep "\[profile" ~/.aws/config | sed "s|\[profile |\[|g") | sort | uniq)"
if [[ -n $"{credentials_list}" ]]; then if [[ -n $"{credentials_list}" ]]; then
echo -e "Available credentials profiles:\n" echo -e "Available credentials profiles:\n"
for profile in ${credentials_list}; do for profile in ${credentials_list}; do
@ -64,12 +64,14 @@ function __awskeys_show {
} }
function __awskeys_export { function __awskeys_export {
local p_keys=( $(__awskeys_get $1 | tr -d " ") ) if [[ $(__awskeys_list) == *"$1"* ]]; then
if [[ -n "${p_keys}" ]]; then local p_keys=( $(__awskeys_get $1 | tr -d " ") )
for p_key in ${p_keys[@]}; do if [[ -n "${p_keys}" ]]; then
local key="${p_key%=*}" for p_key in ${p_keys[@]}; do
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}" local key="${p_key%=*}"
done export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
done
fi
export AWS_DEFAULT_PROFILE="$1" export AWS_DEFAULT_PROFILE="$1"
else else
echo "Profile $1 not found in credentials file" echo "Profile $1 not found in credentials file"