aws.plugin.zsh 1.4 KB
Newer Older
1
2
_homebrew-installed() {
  type brew &> /dev/null
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  _xit=$?
  if [ $_xit -eq 0 ];then
        # ok , we have brew installed
        # speculatively we check default brew prefix
        if [ -h  /usr/local/opt/awscli ];then
                _brew_prefix="/usr/local/opt/awscli"
        else
                # ok , it is not default prefix
                # this call to brew is expensive ( about 400 ms ), so at least let's make it only once
                _brew_prefix=$(brew --prefix awscli)
        fi
        return 0
   else
        return $_xit
   fi
18
19
20
}

_awscli-homebrew-installed() {
21
  [ -r $_brew_prefix/libexec/bin/aws_zsh_completer.sh ] &> /dev/null
22
23
}

24
25
26
27
28
export AWS_HOME=~/.aws

function agp {
  echo $AWS_DEFAULT_PROFILE
}
29

30
function asp {
31
32
  local rprompt=${RPROMPT/<aws:$(agp)>/}

33
  export AWS_DEFAULT_PROFILE=$1
34
  export AWS_PROFILE=$1
35
36

  export RPROMPT="<aws:$AWS_DEFAULT_PROFILE>$rprompt"
37
}
38

39
function aws_profiles {
Frank Wittig's avatar
Frank Wittig committed
40
  reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
41
42
}
compctl -K aws_profiles asp
43

Hosh's avatar
Hosh committed
44
45
46
if which aws_zsh_completer.sh &>/dev/null; then
  _aws_zsh_completer_path=$(which aws_zsh_completer.sh 2>/dev/null)
elif _homebrew-installed && _awscli-homebrew-installed; then
47
  _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
48
fi
Superbil's avatar
Superbil committed
49

Hosh's avatar
Hosh committed
50
[ -n "$_aws_zsh_completer_path" ] && [ -x $_aws_zsh_completer_path ] && source $_aws_zsh_completer_path
Superbil's avatar
Superbil committed
51
unset _aws_zsh_completer_path