-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash
163 lines (145 loc) · 4.38 KB
/
bash
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#source /usr/share/git-core/contrib/completion/git-prompt.sh
alias awsid='aws sts get-caller-identity && aws iam list-account-aliases --query "AccountAliases[]" --output text'
alias ec2instances='aws ec2 describe-instances --query "Reservations[].Instances[?State.Name=='\''running'\''].{Internal:PrivateDnsName,External:PublicDnsName,Name:Tags[?Key=='\''Name'\''].Value,Id:InstanceId}|[].{Id:Id,Internal:Internal,External:External,Name:Name[0]}" --output table'
alias cfnexports='aws cloudformation list-exports --query "Exports[].[Name,Value]" --output table'
complete -C aws_completer aws
awsregion() {
if [[ -z $1 ]]; then
PS3="Please choose an option "
select option in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text --region us-east-1)
do
export AWS_DEFAULT_REGION=$option
export AWS_REGION=$option
break;
done
else
export AWS_DEFAULT_REGION=$1
export AWS_REGION=$1
fi
}
_awsregion() {
if [ $COMP_CWORD -eq 1 ]; then
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W $(aws ec2 describe-regions --query "Regions[].RegionName" --output text --region us-east-1) -- $cur) )
fi
}
complete -F _awsregion awsregion
awsprofile() {
if [[ -z $1 ]]; then
echo "missing profile name"
else
export AWS_DEFAULT_PROFILE=$1
export AWS_PROFILE=$1
fi
}
_awsprofile_list() {
cat ~/.aws/config | grep "\[profile" | sed "s/\[profile \(.*\)\]/\1/"
}
_awsprofile() {
if [ $COMP_CWORD -eq 1 ]; then
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "$(_awsprofile_list)" -- $cur) )
fi
}
complete -F _awsprofile awsprofile
#GIT aliases
alias gis='git status'
alias gic='git commit'
alias gia='git add'
alias gil="git log --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(red)%d%C(reset)'"
alias gid='git diff'
alias gpull='git pull'
alias gpush='git push'
__gia () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command add
}
__gic () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command commit
}
__gil () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command log
}
__gid () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command diff
}
__gis () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command status
}
__gpull () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command pull
}
__gpush () {
local cur=${COMP_WORDS[COMP_CWORD]}
local cword=$COMP_CWORD
__git_complete_command push
}
complete -F __gic gic
complete -F __gia gia
complete -F __gil gil
complete -F __gis gis
complete -F __gid gid
complete -F __gpull gpull
complete -F __gpush gpush
# configure git bash extension
export GIT_PS1_SHOWDIRTYSTATE='true'
export GIT_PS1_SHOWSTASHSTATE='true'
export GIT_PS1_SHOWUNTRACKEDFILES='true'
alias tsnode='node -r ts-node/register'
alias pj='npx projen'
alias cdk='npx cdk'
alias cdka='npx cdk -a cdk.out'
alias cdkw='npx cdkw'
alias l='ls -lah'
alias ..='cd ..'
alias psa='ps axu'
alias rm='rm -i'
alias myip='curl http://icanhazip.com'
alias npmclean='rm -rf node_modules/ package-lock.json yarn.lock'
alias mvntest='mvn clean verify'
alias gpgkey='GPG_TTY=$(tty) && export GPG_TTY && gpg --import --pinentry-mode loopback <(echo $GPG_KEY)'
search () {
if [[ -z $1 ]]; then
echo "Usage: search <text>";
else
grep -Rn "$1" .
fi
}
__mvn_version() {
if [[ -f pom.xml ]]; then
pomVersion=$(xpath pom.xml "/project/version/text()" 2>/dev/null)
echo $" ($(printf '\xe2\x93\x82') ${pomVersion})"
fi
}
__npm_version() {
if [[ -f package.json ]]; then
npmVersion=$(jp -f package.json -u "version" 2>/dev/null)
echo $" ($(printf '\xe2\x93\x83') ${npmVersion})"
fi
}
__aws_profile() {
if [[ ! -z "${AWS_PROFILE}" ]]; then
echo $" ($(printf '\xe2\x92\xb6') ${AWS_PROFILE})"
elif [[ ! -z "${AWS_IDENTITY}" ]]; then
echo $" ($(printf '\xe2\x92\xb6') ${AWS_IDENTITY})"
elif [[ ! -z "${AWS_VAULT}" ]]; then
echo $" ($(printf '\xe2\x92\xb6') ${AWS_VAULT})"
fi
}
__aws_region() {
if [[ ! -z "${AWS_REGION}" ]]; then
echo $" ($(printf '\xf0\x9f\x8c\x90') ${AWS_REGION})"
fi
}
export PS1='[\u \W$(__git_ps1 " (%s)")$(__mvn_version)$(__npm_version)$(__aws_profile)$(__aws_region)]\$ '