aws.plugin.zsh 1.31 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
40
41
42
43
function aws_profiles {
  reply=($(grep profile $AWS_HOME/config|sed -e 's/.*profile \([a-zA-Z0-9_-]*\).*/\1/'))
}

compctl -K aws_profiles asp
44
45

if _homebrew-installed && _awscli-homebrew-installed ; then
46
  _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
47
else
Superbil's avatar
Superbil committed
48
  _aws_zsh_completer_path=$(which aws_zsh_completer.sh)
49
fi
Superbil's avatar
Superbil committed
50
51
52

[ -x $_aws_zsh_completer_path ] && source $_aws_zsh_completer_path
unset _aws_zsh_completer_path