-
Notifications
You must be signed in to change notification settings - Fork 4
/
aaws.sh
executable file
·66 lines (53 loc) · 1.29 KB
/
aaws.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
function _aaws_PS1()
{
if [ -z "$AWS_PROFILE" ]; then
return 0
fi
echo $AAWS_AUTOCOMPLETE | while read e; do
if [[ "$AWS_PROFILE" == "$e" ]]; then
printf "\e[30;1m[$AWS_PROFILE]\e[0m 🔐 "
return 0
fi
done
}
PS1="\$(_aaws_PS1)$PS1"
function aaws()
{
export AAWS_AUTOCOMPLETE="$(grep '^\[' ~/.aws/credentials ~/.aws/config | cut -d : -f2 | sed -r -e 's/^\[profile /[/g' -e 's/\[|\]//g' | uniq)"
complete -W "$AAWS_AUTOCOMPLETE" aaws
if [[ "-h " == "$@ " ]] || [[ "--help " == "$@ " ]]
then
echo "usages: aaws [options] [profile]"
echo ""
echo " aaws - Clear the current profile"
echo " aaws -h - Display help text"
echo " aaws -l - Lists the available profiles"
echo " aaws prod - Set your AWS_PROFILE to prod"
return 0
fi
if [[ "-q " == "$@ " ]]; then
return 0
fi
if [ -z "$@" ]; then
unset AWS_PROFILE
return 0
fi
if [[ "-l" == "$@" ]]; then
echo $AAWS_AUTOCOMPLETE | while read e; do
echo " $e"
done
return 0
fi
echo $AAWS_AUTOCOMPLETE | while read e; do
if [[ "$@" == "$e" ]]; then
export AWS_PROFILE=$@
return 0
fi
done
echo $@ "profile does not exist"
return 1
}
# Set the autocomplete vars
aaws -q
complete -W "$AAWS_AUTOCOMPLETE" aaws