-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile
221 lines (203 loc) · 4.76 KB
/
profile
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
export EDITOR=vim
export PAGER="less -R"
if [ -f /proc/cpuinfo ]; then
export NUMCPUCORES="$(nproc)"
fi
if [ -z "$LOCALPROFILEREAD" ]; then
export PATH="$HOME/bin:/x/bin:$PATH"
export BUILD_ROOT=/x/build
export GOPATH=/x
export GOBIN=/x/bin
if [ -d $HOME/perl5 ]; then
eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
fi
if [ -d $HOME/.rbenv ]; then
export PATH="$HOME/.rbenv/bin:$PATH"
fi
fi
# aliases
alias less='less -R' # recognise color characters
if hash mpc &>/dev/null; then
alias m=mpc
alias mi='mpc idle player; mpc'
fi
if hash ncmpcpp &>/dev/null; then
alias ncmpc=ncmpcpp
fi
if [ "$(uname)" = "Linux" ]; then
alias ls='ls --color=auto'
fi
if [ -f /usr/bin/steam ]; then
alias steam="nice -n10 /usr/bin/steam"
fi
if grep ID=arch /etc/os-release &>/dev/null; then
alias p=pacman-wrapper
fi
if hash pwget &>/dev/null; then
pwcopy() {
pwget "$@" | xsel -bi
}
fi
if hash units &>/dev/null; then
alias units="units --verbose"
fi
cg() {
local REPO_PATH="$(rtree get "$1")"
[ $? -eq 0 ] && cd "${REPO_PATH}"
}
if hash rg &>/dev/null; then
rg() {
# force ripgrep output to look like on a tty, even when sent to less(1)
env rg --heading --color always --line-number "$@"
}
fi
if hash mpv &>/dev/null; then
mpv() {
if [ $# -eq 0 ]; then
env mpv "$(xsel -b)"
else
env mpv "$@"
fi
}
fi
if hash youtube-dl &>/dev/null; then
youtube-dl() {
if [ $# -eq 0 ]; then
env youtube-dl -f best "$(xsel -b)"
else
env youtube-dl "$@"
fi
}
fi
# for OpenStack
if [ -f "$HOME/.local/bin/openstack" ]; then
cloud_is() {
eval "$(/x/src/github.com/majewsky/devenv/env_for_cloud.rb $1)"
env | grep '^OS_' | sed '/^OS_PASSWORD=/s/=.*/=<hidden>/' | sort
if [ -z "$OS_PASSWORD" ]; then
echo -n "OS_PASSWORD="
read -s OS_PASSWORD && export OS_PASSWORD
if [ -n "$OS_PASSWORD" ]; then
echo "<hidden>"
else
echo "<not set>"
fi
fi
}
fi
# for Ruby
if [ -d $HOME/.rbenv ]; then
eval "$(rbenv init -)"
fi
if hash foreman &>/dev/null; then
foreman() {
[ -f .procfile ] && env foreman "$@" -f .procfile || env foreman "$@"
}
fi
if hash kubectl &>/dev/null; then
kc() {
case $# in
1)
kubectl config use-context "$1"
echo "" > ~/.kubectl-namespace
;;
2)
kubectl config use-context "$1"
echo "$2" > ~/.kubectl-namespace
;;
*)
echo "usage: kc <context> [namespace]" >&2
return 1
;;
esac
}
kn() {
case $# in
0)
echo "" > ~/.kubectl-namespace
;;
1)
echo "$1" > ~/.kubectl-namespace
;;
*)
echo "usage: kn [namespace]" >&2
return 1
;;
esac
}
k() {
local KUBECTL
local KUBECTL_NAMESPACE="$(cat ~/.kubectl-namespace)"
if [ "${KUBECTL_NAMESPACE}" != "" ]; then
KUBECTL=(kubectl --namespace="$KUBECTL_NAMESPACE")
else
KUBECTL=kubectl
fi
case "$1" in
sh)
shift
${KUBECTL} exec -ti "$@" -- env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM /bin/sh
;;
bash)
shift
${KUBECTL} exec -ti "$@" -- env COLUMNS=$COLUMNS LINES=$LINES TERM=$TERM /bin/bash
;;
yaml)
shift
${KUBECTL} get "$@" -o yaml
;;
*)
${KUBECTL} "$@"
;;
esac
}
if hash helm &>/dev/null; then
# Synopsis: h <upgrade|diff> [chart-directory] [options]
#
# Call `helm upgrade` or `helm diff` on the chart in that directory, using the appropriate
# values.yaml from $HELM_SECRETS_REPO. If no directory is given, use the working directory.
# Any additional options are passed on to "helm upgrade".
hu() {
(
local COMMAND="$1"
shift
case "${1:-empty}" in
-*|empty)
;;
*)
cd "$1"
shift
;;
esac
if [ ! -f Chart.yaml ]; then
echo "Chart.yaml: file not found" >&2
return 1
fi
if [ -z "${HELM_SECRETS_REPO}" ]; then
echo "\$HELM_SECRETS_REPO not set!" >&2
return 1
fi
git -C "${HELM_SECRETS_REPO}" pull | grep -v 'master is up to date'
CHART_NAME="$(awk '/name:/{print$2}' Chart.yaml)"
CONTEXT_NAME="$(kubectl config current-context)"
VALUES_FILE="$(find "${HELM_SECRETS_REPO}/${CONTEXT_NAME}/values" -name "${CHART_NAME}.yaml" | head -n1)"
if [ ! -f "${VALUES_FILE}" ]; then
echo "no values.yaml found for ${CHART_NAME} in ${CONTEXT_NAME}" >&2
return 1
fi
GLOBALS_FILE="${HELM_SECRETS_REPO}/${CONTEXT_NAME}/values/globals.yaml"
if [ ! -f "${GLOBALS_FILE}" ]; then
echo "no globals.yaml found in ${CONTEXT_NAME}" >&2
return 1
fi
if [ "${CONTEXT_NAME}" != staging -a "${COMMAND}" = upgrade -a "${I_KNOW_THIS_IS_PROD:-}" != yes ]; then
echo "Not upgrading a productive region without I_KNOW_THIS_IS_PROD=yes." >&2
return 1
fi
helm "${COMMAND}" "${CHART_NAME}" --values "${GLOBALS_FILE}" --values "${VALUES_FILE}" --reset-values "$@" .
)
}
fi
fi
# this must always be at the end
export LOCALPROFILEREAD="yes"