aws.plugin.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # AWS profile selection
  2. function agp {
  3. echo $AWS_PROFILE
  4. }
  5. function asp {
  6. export AWS_DEFAULT_PROFILE=$1
  7. export AWS_PROFILE=$1
  8. if [[ -z "$1" ]]; then
  9. echo AWS profile cleared.
  10. fi
  11. }
  12. function aws_profiles {
  13. reply=($(grep '\[profile' "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
  14. }
  15. compctl -K aws_profiles asp
  16. # AWS prompt
  17. function aws_prompt_info() {
  18. [[ -z $AWS_PROFILE ]] && return
  19. echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_SUFFIX:=>}"
  20. }
  21. if [ "$SHOW_AWS_PROMPT" != false ]; then
  22. export RPROMPT='$(aws_prompt_info)'"$RPROMPT"
  23. fi
  24. # Load awscli completions
  25. _awscli-homebrew-installed() {
  26. # check if Homebrew is installed
  27. (( $+commands[brew] )) || return 1
  28. # speculatively check default brew prefix
  29. if [ -h /usr/local/opt/awscli ]; then
  30. _brew_prefix=/usr/local/opt/awscli
  31. else
  32. # ok, it is not in the default prefix
  33. # this call to brew is expensive (about 400 ms), so at least let's make it only once
  34. _brew_prefix=$(brew --prefix awscli)
  35. fi
  36. }
  37. # get aws_zsh_completer.sh location from $PATH
  38. _aws_zsh_completer_path="$commands[aws_zsh_completer.sh]"
  39. # otherwise check if installed via Homebrew
  40. if [[ -z $_aws_zsh_completer_path ]] && _awscli-homebrew-installed; then
  41. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  42. else
  43. _aws_zsh_completer_path=/usr/share/zsh/site-functions/aws_zsh_completer.sh
  44. fi
  45. [[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
  46. unset _aws_zsh_completer_path _brew_prefix