awsctx
Very simple and basic script to switch faster between contexts in AWS CLI.
Usage
$ awsall
Lists all available profiles.
$ awsctx
Shows current profile.
$ awsctx $PROFILE_NAME
Switches AWS CLI to $PROFILE_NAME
$ aws configure --profile $PROFILE_NAME
Creates the profile $PROFILE_NAME for AWS CLI usage
See AWS CLI Configure multiple profiles for more informations on how to create multiple profiles.
Installation
Linux
- For bash:
git clone https://github.com/OlivierDupre/awsctx.git ~/.awsctx
# COMPDIR='/usr/share/bash-completion/completions'
COMPDIR=$(pkg-config --variable=completionsdir bash-completion)
ln -sf ~/.awsctx/completion/awsctx.bash $COMPDIR/awsctx
nb_definitions=`grep awsctx ~/.bashrc | wc -l`
if [ $nb_definitions -eq 0 ]; then
cat << FOE >> ~/.bashrc
# awsctx
source ~/.awsctx/.awsctx
FOE
fi
nb_definitions=`grep trim ~/.bashrc | wc -l`
if [ $nb_definitions -eq 0 ]; then
cat << FOE >> ~/.bashrc
function trim
{
echo "$1" | xargs
}
FOE
fi
- For zsh:
git clone https://github.com/OlivierDupre/awsctx.git ~/.awx
mkdir -p ~/.zsh/completion
ln -s ~/.awx/completion/awx.zsh ~/.zsh/completion/_awx.zsh
nb_definitions=`grep completion ~/.zshrc | wc -l`
if [ $nb_definitions -eq 0 ]; then
cat << FOE >> ~/.zshrc
fpath=(~/.zsh/completion $fpath)
FOE
fi
mv ~/.awx/.awsctx ~/.zsh/.awsctx
Then copy
and paste
the following line to your ~/.zshrc
file.
[[ -d ~/.zsh ]] && for f (~/.zsh/*(.)) { [[ -f $f ]] && source $f } && for f (~/.zsh/.*(.)) { [[ -f $f ]] && source $f }
Thanks to...
- Freely inspired by kubectx and the very good job done by @ahmetb.
- Using
trim
functions defined by @NOYB on Stackoverflow