aws.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. _homebrew-installed() {
  2. type brew &> /dev/null
  3. _xit=$?
  4. if [ $_xit -eq 0 ];then
  5. # ok , we have brew installed
  6. # speculatively we check default brew prefix
  7. if [ -h /usr/local/opt/awscli ];then
  8. _brew_prefix="/usr/local/opt/awscli"
  9. else
  10. # ok , it is not default prefix
  11. # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
  12. _brew_prefix=$(brew --prefix awscli)
  13. fi
  14. return 0
  15. else
  16. return $_xit
  17. fi
  18. }
  19. _awscli-homebrew-installed() {
  20. [ -r $_brew_prefix/libexec/bin/aws_zsh_completer.sh ] &> /dev/null
  21. }
  22. export AWS_HOME=~/.aws
  23. function agp {
  24. echo $AWS_DEFAULT_PROFILE
  25. }
  26. function asp {
  27. local rprompt=${RPROMPT/<aws:$(agp)>/}
  28. export AWS_DEFAULT_PROFILE=$1
  29. export AWS_PROFILE=$1
  30. export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>$rprompt"
  31. }
  32. function aws_profiles {
  33. reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
  34. }
  35. compctl -K aws_profiles asp
  36. if which aws_zsh_completer.sh &>/dev/null; then
  37. _aws_zsh_completer_path=$(which aws_zsh_completer.sh 2>/dev/null)
  38. elif _homebrew-installed && _awscli-homebrew-installed; then
  39. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  40. fi
  41. [ -n "$_aws_zsh_completer_path" ] && [ -x $_aws_zsh_completer_path ] && source $_aws_zsh_completer_path
  42. unset _aws_zsh_completer_path