aws.plugin.zsh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 common locations
  54. if [[ -z $_aws_zsh_completer_path ]]; then
  55. # Homebrew
  56. if _awscli-homebrew-installed; then
  57. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  58. # Ubuntu
  59. elif [[ -e /usr/share/zsh/vendor-completions/_awscli ]]; then
  60. _aws_zsh_completer_path=/usr/share/zsh/vendor-completions/_awscli
  61. # RPM
  62. else
  63. _aws_zsh_completer_path=/usr/share/zsh/site-functions/aws_zsh_completer.sh
  64. fi
  65. fi
  66. [[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
  67. unset _aws_zsh_completer_path _brew_prefix