-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.bashrc.aliases
More file actions
163 lines (129 loc) · 3.79 KB
/
bash.bashrc.aliases
File metadata and controls
163 lines (129 loc) · 3.79 KB
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
# general
alias docker='finch'
alias cp='cp -i'
alias df='df -kTh'
alias diff='colordiff'
alias du='du -kh'
alias gr='git fetch upstream; git rebase upstream/$(git branch --show-current)'
alias h='history'
alias ll='ls -l'
alias ls='ls -F'
alias mv='mv -i'
alias rm='rm -i'
alias vi='vim'
alias md5='md5 -r'
alias watch='watch '
alias tree='tree -aFI .git'
# python
alias pycodestyle='pycodestyle --ignore=E501'
# kubernetes
if [ $commands[kubectl] ]; then
source <(kubectl completion zsh)
fi
# kubectl
alias k='kubectl'
alias kd='kubectl describe'
alias kg='kubectl get'
alias kgn='kubectl get nodes'
alias kgnw='kubectl get nodes -o wide'
alias kgna='kubectl get nodes -o wide --label-columns="node.kubernetes.io/instance-type,topology.kubernetes.io/zone"'
alias kgp='kubectl get pods'
alias kgpw='kubectl get pods -o wide'
alias kgpa='kubectl get pods --all-namespaces'
alias kgpaw='kubectl get pods -o wide --all-namespaces'
alias kgpas='kubectl get pods -o wide --all-namespaces --sort-by spec.nodeName'
# eks specific
function get-instance-id-by-node() {
[ $# -ne 1 ] && return
kubectl get nodes $1 -o jsonpath='{.spec.providerID}' | cut -d'/' -f5
}
function ssm-into-ec2-node() {
aws ssm start-session --target ${1}
}
function ssm-into-eks-node() {
local TARGET=$(kubectl get nodes $1 -o jsonpath='{.spec.providerID}' | cut -d'/' -f5)
aws ssm start-session --target ${TARGET}
}
# golang
function go-setup() {
local GOVERSION=$1
local FORCE=$2
local PKG_REMOTE_PATH="https://go.dev/dl/go${GOVERSION}.darwin-amd64.tar.gz"
local PKG_OUTPUT_PATH="/tmp/go${GOVERSION}.darwin-amd64.tar.gz"
local PKG_EXTRACT_PATH="/tmp/go-${GOVERSION}"
local PKG_TARGET_PATH="/usr/local/go-${GOVERSION}"
if [ -z "${GOVERSION}" ]; then
echo "abort, please specify the version to install."
return
fi
if [ -e "${PKG_TARGET_PATH}" ]; then
if [ "${FORCE}" != "force" ]; then
echo "abort, target version already existed."
return
fi
rm -f ${PKG_OUTPUT_PATH}
fi
if [ ! -f "${PKG_OUTPUT_PATH}" ]; then
wget ${PKG_REMOTE_PATH} -O ${PKG_OUTPUT_PATH} --no-verbose --show-progress
fi
rm -rf ${PKG_EXTRACT_PATH}
mkdir -p ${PKG_EXTRACT_PATH}
tar xf ${PKG_OUTPUT_PATH} --strip-components 1 -C ${PKG_EXTRACT_PATH}
if [ $? -ne 0 ]; then
rm -rf ${PKG_EXTRACT_PATH}
else
echo "Hint: password might be required to finish setup"
sudo rm -rf ${PKG_TARGET_PATH}
sudo mv ${PKG_EXTRACT_PATH} ${PKG_TARGET_PATH}
go-switch ${GOVERSION}
fi
rm -f ${PKG_OUTPUT_PATH}
}
function go-switch() {
local GOVERSION=$1
if [ -z "${GOVERSION}" ]; then
find /usr/local -maxdepth 1 -type d -name "go*"
return
fi
if [ ! -d "/usr/local/go-${GOVERSION}" ]; then
return
fi
echo "Hint: password might be required to finish setup"
sudo rm -f /usr/local/go
sudo ln -s -f /usr/local/go-${GOVERSION} /usr/local/go
echo "Hint: check version installed"
go version
}
# misc
function ssl_certs_check() {
echo | openssl s_client -servername $1 -connect $1:443 2>/dev/null | openssl x509 -noout -dates
}
function remove_color() {
# https://unix.stackexchange.com/questions/140251/strip-color-on-os-x-with-bsd-sed-or-any-other-tool
sed -e "s,$(printf '\033')\\[[0-9;]*[a-zA-Z],,g" $1
}
function cleanup_history() {
rm -rf ~/.DS_Store
rm -rf ~/.calc_history
rm -rf ~/.config/gcloud/logs
rm -rf ~/.httpie
rm -rf ~/.lesshst
rm -rf ~/.mysql_history
rm -rf ~/.oracle_jre_usage
rm -rf ~/.python_history
rm -rf ~/.rediscli_history
rm -rf ~/.sqlite_history
rm -rf ~/.terraform.d/checkpoint_*
rm -rf ~/.wget-hsts
rm -rf ~/.z
rm -rf ~/.zsh_history
rm -rf ~/.zshrc.bak
rm -rf ~/.zshrc.zwc
find ~/.vagrant.d/boxes -type d -exec rmdir {} \; 2>/dev/null
}
function secure_remove() {
shred -u -n 9 $@
}
function ipinfo() {
curl -s ipconfig.io/json | jq .
}