aws.plugin.zsh 1.39 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
function agp {
25
  echo $AWS_PROFILE
26
}
27

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

31
  export AWS_DEFAULT_PROFILE=$1
32
  export AWS_PROFILE=$1
33

34
  export RPROMPT="<aws:$AWS_PROFILE>$rprompt"
35
}
36

37
function aws_profiles {
38
  reply=($(grep profile "${AWS_CONFIG_FILE:-$HOME/.aws/config}"|sed -e 's/.*profile \([a-zA-Z0-9_\.-]*\).*/\1/'))
39
40
}
compctl -K aws_profiles asp
41

Hosh's avatar
Hosh committed
42
43
44
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
45
  _aws_zsh_completer_path=$_brew_prefix/libexec/bin/aws_zsh_completer.sh
46
fi
Superbil's avatar
Superbil committed
47

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