aws.plugin.zsh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. export AWS_EB_PROFILE=$1
  9. if [[ -z "$1" ]]; then
  10. echo AWS profile cleared.
  11. fi
  12. }
  13. function aws_change_access_key {
  14. if [[ -z "$1" ]] then
  15. echo "usage: $0 <profile>"
  16. return 1
  17. fi
  18. echo Insert the credentials when asked.
  19. asp "$1"
  20. aws iam create-access-key
  21. aws configure --profile "$1"
  22. echo You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`
  23. echo Your current keys are:
  24. aws iam list-access-keys
  25. }
  26. function aws_profiles {
  27. reply=($(grep '\[profile' "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
  28. }
  29. compctl -K aws_profiles asp aws_change_access_key
  30. # AWS prompt
  31. function aws_prompt_info() {
  32. [[ -z $AWS_PROFILE ]] && return
  33. echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_SUFFIX:=>}"
  34. }
  35. if [ "$SHOW_AWS_PROMPT" != false ]; then
  36. RPROMPT='$(aws_prompt_info)'"$RPROMPT"
  37. fi
  38. # Load awscli completions
  39. _awscli-homebrew-installed() {
  40. # check if Homebrew is installed
  41. (( $+commands[brew] )) || return 1
  42. # speculatively check default brew prefix
  43. if [ -h /usr/local/opt/awscli ]; then
  44. _brew_prefix=/usr/local/opt/awscli
  45. else
  46. # ok, it is not in the default prefix
  47. # this call to brew is expensive (about 400 ms), so at least let's make it only once
  48. _brew_prefix=$(brew --prefix awscli)
  49. fi
  50. }
  51. # get aws_zsh_completer.sh location from $PATH
  52. _aws_zsh_completer_path="$commands[aws_zsh_completer.sh]"
  53. # otherwise check if installed via Homebrew
  54. if [[ -z $_aws_zsh_completer_path ]] && _awscli-homebrew-installed; then
  55. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  56. else
  57. _aws_zsh_completer_path=/usr/share/zsh/site-functions/aws_zsh_completer.sh
  58. fi
  59. [[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
  60. unset _aws_zsh_completer_path _brew_prefix