Skip to content

Instantly share code, notes, and snippets.

@elerch
Created January 28, 2017 00:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elerch/d76c8f5935da13ec5a7889417e35b84f to your computer and use it in GitHub Desktop.
Save elerch/d76c8f5935da13ec5a7889417e35b84f to your computer and use it in GitHub Desktop.
_homebrew-installed() {
type brew &> /dev/null
}
_awscli-homebrew-installed() {
brew list awscli &> /dev/null
}
export AWS_HOME=~/.aws
function agp {
echo $AWS_DEFAULT_PROFILE
}
function asp {
local rprompt=${RPROMPT/<aws:$(agp)>/}
export AWS_DEFAULT_PROFILE=$1
export AWS_PROFILE=$1
export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>$rprompt"
}
function aws_profiles {
reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_-]*\).*/\1/'))
}
compctl -K aws_profiles asp
# This is the default install location for homebrew. brew and
# brew list are very slow, so we'll check the default path first
if [ -f "/usr/local/opt/awscli/libexec/bin/aws_zsh_completer.sh" ]; then
_aws_zsh_completer_path="/usr/local/opt/awscli/libexec/bin/aws_zsh_completer.sh"
elif _homebrew-installed && _awscli-homebrew-installed ; then
_aws_zsh_completer_path=$(brew --prefix awscli)/libexec/bin/aws_zsh_completer.sh
else
_aws_zsh_completer_path=$(which aws_zsh_completer.sh)
fi
[ -x $_aws_zsh_completer_path ] && source $_aws_zsh_completer_path
unset _aws_zsh_completer_path
@juhoautio
Copy link

For me it's at /usr/local/bin/aws_zsh_completer.sh. I just installed oh-my-zsh from scratch, so maybe that's the current default location..

@elerch
Copy link
Author

elerch commented May 3, 2017

Yeah - this falls back to $(which aws_zsh_completer.sh), which will pick up /usr/local/bin. The issue is that running brew --prefix in login scripts is brutally slow, so I'm hardcoding the common paths to avoid calling brew. It's mac specific and will be ignored on other platforms.

@mcreenan
Copy link

mcreenan commented Apr 23, 2021

Thanks for this. I was finally able to reduce oh-my-zsh startup time by a couple of seconds. It had been haunting me for a good year+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment