Skip to content

Instantly share code, notes, and snippets.

@zk-1
Last active August 5, 2020 03:15
Show Gist options
  • Save zk-1/2427bf01b8df7bdad9a88fdf95c724dc to your computer and use it in GitHub Desktop.
Save zk-1/2427bf01b8df7bdad9a88fdf95c724dc to your computer and use it in GitHub Desktop.
A CLI tool to allow quicker changing of the AWS_PROFILE env var. You can save it as /usr/local/bin/chp for easy access
# Name: CHP
# Usage: . chp
# . chp [1|2|3]
# Description: Quickly change the AWS_PROFILE environment variable
# Author: Zoë Kelly (zoe@starshade.ca)
# License: MIT
# Created: 2020
# Updated: 2020
## Note:
# Set your desired values here
choice_1='root'
choice_2='prod'
choice_3='test'
# Check if script is being sourced
([[ -n $ZSH_EVAL_CONTEXT && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)) && sourced=1 || sourced=0
if ([[ $sourced == 0 ]] && [[ $1 != "p" ]]); then
echo "$(tput setaf 1)You must source this tool$(tput sgr 0) e.g.:"
echo "$(tput setaf 4). chp$(tput sgr 0)"
exit 1
fi
if [[ $# == 1 ]]; then
# CLI parameter flow
if [[ $1 == 1 ]]; then
export AWS_PROFILE=$choice_1
elif [[ $1 == 2 ]]; then
export AWS_PROFILE=$choice_2
elif [[ $1 == 3 ]]; then
export AWS_PROFILE=$choice_3
elif [[ $1 == "p" ]]; then
# p for print
:
else
echo "Invalid choice"
return
fi
else
# "GUI" flow
PS3='Change AWS_PROFILE to: '
options3=("$choice_1" "$choice_2" "$choice_3")
select opt3 in "${options3[@]}"
do
case $opt3 in
"$choice_1")
export AWS_PROFILE=$choice_1
break
;;
"$choice_2")
export AWS_PROFILE=$choice_2
break
;;
"$choice_3")
export AWS_PROFILE=$choice_3
break
;;
esac
done
fi
echo "AWS_PROFILE = $AWS_PROFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment