aws.plugin.zsh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 [[ "x$1" == "x" ]] then
  15. echo "usage: $0 <profile.name>"
  16. return 1
  17. else
  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. fi
  26. }
  27. function aws_profiles {
  28. reply=($(grep '\[profile' "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
  29. }
  30. compctl -K aws_profiles asp aws_change_access_key
  31. # AWS prompt
  32. function aws_prompt_info() {
  33. [[ -z $AWS_PROFILE ]] && return
  34. echo "${ZSH_THEME_AWS_PREFIX:=<aws:}${AWS_PROFILE}${ZSH_THEME_AWS_SUFFIX:=>}"
  35. }
  36. if [ "$SHOW_AWS_PROMPT" != false ]; then
  37. export RPROMPT='$(aws_prompt_info)'"$RPROMPT"
  38. fi
  39. # Load awscli completions
  40. _awscli-homebrew-installed() {
  41. # check if Homebrew is installed
  42. (( $+commands[brew] )) || return 1
  43. # speculatively check default brew prefix
  44. if [ -h /usr/local/opt/awscli ]; then
  45. _brew_prefix=/usr/local/opt/awscli
  46. else
  47. # ok, it is not in the default prefix
  48. # this call to brew is expensive (about 400 ms), so at least let's make it only once
  49. _brew_prefix=$(brew --prefix awscli)
  50. fi
  51. }
  52. # get aws_zsh_completer.sh location from $PATH
  53. _aws_zsh_completer_path="$commands[aws_zsh_completer.sh]"
  54. # otherwise check if installed via Homebrew
  55. if [[ -z $_aws_zsh_completer_path ]] && _awscli-homebrew-installed; then
  56. _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
  57. else
  58. _aws_zsh_completer_path=/usr/share/zsh/site-functions/aws_zsh_completer.sh
  59. fi
  60. [[ -r $_aws_zsh_completer_path ]] && source $_aws_zsh_completer_path
  61. unset _aws_zsh_completer_path _brew_prefix