Last active
November 26, 2022 21:23
-
-
Save jazlopez/63d6d6e812de442a43360367b76eafcb to your computer and use it in GitHub Desktop.
Bash custom function and profile autocomplete to list available zones for a given profile.
This file contains hidden or 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
| # ============================================================================================= | |
| # Bash custom function and profile autocomplete to list available zones for a given profile. | |
| # Jaziel Lopez jazlopez @ github.com | |
| # 2022 | |
| # ============================================================================================= | |
| # -- | |
| # list aws profiles from default aws credentials file | |
| # -- | |
| function _completion_aws_profile_names_(){ | |
| grep -Eo "\[.*\]" $HOME/.aws/credentials | sed 's/[][]//g' | |
| } | |
| function _list_available_zones_() { | |
| clear | |
| echo "[INFO] usage: list-available-zones [aws_profile]" | |
| echo "\tif argument [aws_profile] not provided it uses default" | |
| echo "========================================================================" | |
| local profile="default" | |
| [[ ! -z "${AWS_PROFILE}" ]] && profile="${AWS_PROFILE}" | |
| [[ ! -z "${1}" ]] && profile="${1}" | |
| echo "[INFO] list AWS available zones for profile $profile" | |
| aws ec2 describe-availability-zones --profile "${profile}" | jq -r '.AvailabilityZones | .[] | .ZoneName' | |
| } | |
| complete -F _completion_aws_profile_names_ _list_available_zones_ | |
| alias list-available-zones=_list_available_zones_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment