Skip to content

Instantly share code, notes, and snippets.

@auser
Created August 6, 2009 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save auser/163475 to your computer and use it in GitHub Desktop.
Save auser/163475 to your computer and use it in GitHub Desktop.
export JAVA_HOME="/usr"
export EC2_HOME=~/.ec2
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
export PATH=$EC2_HOME/bin:$PATH
export EC2_CONFIG_DIR=$EC2_HOME/keys
ec2-switch-context() {
if [[ -z $1 || ! -d $EC2_HOME/$1 ]]; then
echo "Usage: ec2-switch-context <context_name>";
return 1;
fi
echo "Switching to ec2 context: $1"
rm -rf $EC2_HOME/current
ln -Fs $EC2_HOME/$1 $EC2_HOME/current;
ec2-reload-current-context;
}
ec2-reload-current-context() {
if [ ! -d $EC2_HOME/current ]; then
echo "There's no 'current' context defined";
return 1;
fi
if [ -f $EC2_HOME/current/pk-*.pem ]; then
export EC2_PRIVATE_KEY=`ls $EC2_HOME/current/pk-*.pem`;
fi
if [ -f $EC2_HOME/current/cert-*.pem ]; then
export EC2_CERT=`ls $EC2_HOME/current/cert-*.pem`;
fi
if [ -f $EC2_HOME/current/environment ]; then
source $EC2_HOME/current/environment;
fi
return 0;
}
_ec2_contexts() {
COMPREPLY=($(compgen -W "$(ls $EC2_HOME | grep -v 'bin\|lib\|config\|current')" -- ${COMP_WORDS[COMP_CWORD]}));
return 0;
}
complete -F _ec2_contexts -o default ec2-switch-context;
ec2-reload-current-context &> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment