aws.plugin.zsh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. function agp {
  23. echo $AWS_PROFILE
  24. }
  25. function asp {
  26. local rprompt=${RPROMPT/<aws:$(agp)>/}
  27. export AWS_DEFAULT_PROFILE=$1
  28. export AWS_PROFILE=$1
  29. export RPROMPT="<aws:$AWS_PROFILE>$rprompt"
  30. }
  31. function aws_profiles {
  32. reply=($(grep profile "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
  33. }
  34. compctl -K aws_profiles asp
  35. if which aws_zsh_completer.sh &>/dev/null; then
  36. _aws_zsh_completer_path=$(which aws_zsh_completer.sh 2>/dev/null)
  37. elif _homebrew-installed && _awscli-homebrew-installed; then
  38. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  39. fi
  40. [ -n "$_aws_zsh_completer_path" ] && [ -x $_aws_zsh_completer_path ] && source $_aws_zsh_completer_path
  41. unset _aws_zsh_completer_path