-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
458 lines (376 loc) · 13.2 KB
/
.bashrc
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# bdirito custom
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo " (${BRANCH}${STAT})"
else
echo ""
fi
}
# get current status of git repo
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
# on windows use runemacs to not lock the shell
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
alias emacs=runemacs
fi
PROMPT_WARN="false"
RED=$'\e[1;31m'
GREEN=$'\e[1;32m'
YELLOW=$'\e[1;33m'
BLUE=$'\e[1;34m'
MAGNENTA=$'\e[1;35m'
CYAN=$'\e[1;36m'
NOCOLOR=$'\e[0m'
KUBE_PS1_SYMBOL_ENABLE=false
KUBE_PS1_CLUSTER_FUNCTION=get_kube_cluster
KUBE_PS1_NAMESPACE_FUNCTION=get_kube_ns
# put context on global scope
KUBE_PS1_NAMESPACE=""
## start copypasta
# Kubernetes prompt helper for bash/zsh
# Displays current context and namespace
# Copyright 2018 Jon Mosco
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Debug
[[ -n $DEBUG ]] && set -x
# Default values for the prompt
# Override these values in ~/.zshrc or ~/.bashrc
KUBE_PS1_BINARY="${KUBE_PS1_BINARY:-kubectl}"
KUBE_PS1_SYMBOL_ENABLE="${KUBE_PS1_SYMBOL_ENABLE:-true}"
KUBE_PS1_SYMBOL_DEFAULT="${KUBE_PS1_SYMBOL_DEFAULT:-\u2388 }"
KUBE_PS1_SYMBOL_USE_IMG="${KUBE_PS1_SYMBOL_USE_IMG:-false}"
KUBE_PS1_NS_ENABLE="${KUBE_PS1_NS_ENABLE:-true}"
KUBE_PS1_PREFIX="${KUBE_PS1_PREFIX-(}"
KUBE_PS1_SEPARATOR="${KUBE_PS1_SEPARATOR-|}"
KUBE_PS1_DIVIDER="${KUBE_PS1_DIVIDER-:}"
KUBE_PS1_SUFFIX="${KUBE_PS1_SUFFIX-)}"
KUBE_PS1_SYMBOL_COLOR="${KUBE_PS1_SYMBOL_COLOR-blue}"
KUBE_PS1_CTX_COLOR="${KUBE_PS1_CTX_COLOR-red}"
KUBE_PS1_NS_COLOR="${KUBE_PS1_NS_COLOR-cyan}"
KUBE_PS1_BG_COLOR="${KUBE_PS1_BG_COLOR}"
KUBE_PS1_KUBECONFIG_CACHE="${KUBECONFIG}"
KUBE_PS1_DISABLE_PATH="${HOME}/.kube/kube-ps1/disabled"
KUBE_PS1_UNAME=$(uname)
KUBE_PS1_LAST_TIME=0
KUBE_PS1_CLUSTER_FUNCTION="${KUBE_PS1_CLUSTER_FUNCTION}"
KUBE_PS1_NAMESPACE_FUNCTION="${KUBE_PS1_NAMESPACE_FUNCTION}"
# Determine our shell
if [ "${ZSH_VERSION-}" ]; then
KUBE_PS1_SHELL="zsh"
elif [ "${BASH_VERSION-}" ]; then
KUBE_PS1_SHELL="bash"
fi
_kube_ps1_color_fg() {
local KUBE_PS1_FG_CODE
case "${1}" in
black) KUBE_PS1_FG_CODE=0;;
red) KUBE_PS1_FG_CODE=1;;
green) KUBE_PS1_FG_CODE=2;;
yellow) KUBE_PS1_FG_CODE=3;;
blue) KUBE_PS1_FG_CODE=4;;
magenta) KUBE_PS1_FG_CODE=5;;
cyan) KUBE_PS1_FG_CODE=6;;
white) KUBE_PS1_FG_CODE=7;;
# 256
[0-9]|[1-9][0-9]|[1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-6]) KUBE_PS1_FG_CODE="${1}";;
*) KUBE_PS1_FG_CODE=default
esac
if [[ "${KUBE_PS1_FG_CODE}" == "default" ]]; then
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
return
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
KUBE_PS1_FG_CODE="%F{$KUBE_PS1_FG_CODE}"
elif [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then
if tput setaf 1 &> /dev/null; then
KUBE_PS1_FG_CODE="$(tput setaf ${KUBE_PS1_FG_CODE})"
elif [[ $KUBE_PS1_FG_CODE -ge 0 ]] && [[ $KUBE_PS1_FG_CODE -le 256 ]]; then
KUBE_PS1_FG_CODE="\033[38;5;${KUBE_PS1_FG_CODE}m"
else
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_FG}"
fi
fi
echo ${_KUBE_PS1_OPEN_ESC}${KUBE_PS1_FG_CODE}${_KUBE_PS1_CLOSE_ESC}
}
_kube_ps1_color_bg() {
local KUBE_PS1_BG_CODE
case "${1}" in
black) KUBE_PS1_BG_CODE=0;;
red) KUBE_PS1_BG_CODE=1;;
green) KUBE_PS1_BG_CODE=2;;
yellow) KUBE_PS1_BG_CODE=3;;
blue) KUBE_PS1_BG_CODE=4;;
magenta) KUBE_PS1_BG_CODE=5;;
cyan) KUBE_PS1_BG_CODE=6;;
white) KUBE_PS1_BG_CODE=7;;
# 256
[0-9]|[1-9][0-9]|[1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-6]) KUBE_PS1_BG_CODE="${1}";;
*) KUBE_PS1_BG_CODE=$'\033[0m';;
esac
if [[ "${KUBE_PS1_BG_CODE}" == "default" ]]; then
KUBE_PS1_FG_CODE="${_KUBE_PS1_DEFAULT_BG}"
return
elif [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
KUBE_PS1_BG_CODE="%K{$KUBE_PS1_BG_CODE}"
elif [[ "${KUBE_PS1_SHELL}" == "bash" ]]; then
if tput setaf 1 &> /dev/null; then
KUBE_PS1_BG_CODE="$(tput setab ${KUBE_PS1_BG_CODE})"
elif [[ $KUBE_PS1_BG_CODE -ge 0 ]] && [[ $KUBE_PS1_BG_CODE -le 256 ]]; then
KUBE_PS1_BG_CODE="\033[48;5;${KUBE_PS1_BG_CODE}m"
else
KUBE_PS1_BG_CODE="${DEFAULT_BG}"
fi
fi
echo ${OPEN_ESC}${KUBE_PS1_BG_CODE}${CLOSE_ESC}
}
_kube_ps1_binary_check() {
command -v $1 >/dev/null
}
_kube_ps1_symbol() {
[[ "${KUBE_PS1_SYMBOL_ENABLE}" == false ]] && return
case "${KUBE_PS1_SHELL}" in
bash)
if ((BASH_VERSINFO[0] >= 4)) && [[ $'\u2388 ' != "\\u2388 " ]]; then
KUBE_PS1_SYMBOL=$'\u2388 '
KUBE_PS1_SYMBOL_IMG=$'\u2638 '
else
KUBE_PS1_SYMBOL=$'\xE2\x8E\x88 '
KUBE_PS1_SYMBOL_IMG=$'\xE2\x98\xB8 '
fi
;;
zsh)
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_DEFAULT}"
KUBE_PS1_SYMBOL_IMG="\u2638 ";;
*)
KUBE_PS1_SYMBOL="k8s"
esac
if [[ "${KUBE_PS1_SYMBOL_USE_IMG}" == true ]]; then
KUBE_PS1_SYMBOL="${KUBE_PS1_SYMBOL_IMG}"
fi
echo "${KUBE_PS1_SYMBOL}"
}
_kube_ps1_split() {
type setopt >/dev/null 2>&1 && setopt SH_WORD_SPLIT
local IFS=$1
echo $2
}
# TODO: Break this function apart:
# one for context and one for namespace
_kube_ps1_get_context_ns() {
KUBE_PS1_CONTEXT="$(${KUBE_PS1_BINARY} config current-context 2>/dev/null)"
if [[ ! -z "${KUBE_PS1_CLUSTER_FUNCTION}" ]]; then
KUBE_PS1_CONTEXT=$($KUBE_PS1_CLUSTER_FUNCTION $KUBE_PS1_CONTEXT)
fi
if [[ -z "${KUBE_PS1_CONTEXT}" ]]; then
KUBE_PS1_CONTEXT="N/A"
KUBE_PS1_NAMESPACE="N/A"
return
elif [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then
KUBE_PS1_NAMESPACE="$(${KUBE_PS1_BINARY} config view --minify --output 'jsonpath={..namespace}' 2>/dev/null)"
# Set namespace to 'default' if it is not defined
KUBE_PS1_NAMESPACE="${KUBE_PS1_NAMESPACE:-default}"
if [[ ! -z "${KUBE_PS1_NAMESPACE_FUNCTION}" ]]; then
KUBE_PS1_NAMESPACE=$($KUBE_PS1_NAMESPACE_FUNCTION $KUBE_PS1_NAMESPACE)
fi
fi
}
# Build our prompt
kube_ps1() {
_kube_ps1_get_context_ns
local KUBE_PS1
local KUBE_PS1_RESET_COLOR="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_FG}${_KUBE_PS1_CLOSE_ESC}"
# Background Color
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="$(_kube_ps1_color_bg ${KUBE_PS1_BG_COLOR})"
# Prefix
[[ -n "${KUBE_PS1_PREFIX}" ]] && KUBE_PS1+="${KUBE_PS1_PREFIX}"
# Symbol
KUBE_PS1+="$(_kube_ps1_color_fg $KUBE_PS1_SYMBOL_COLOR)$(_kube_ps1_symbol)${KUBE_PS1_RESET_COLOR}"
if [[ -n "${KUBE_PS1_SEPARATOR}" ]] && [[ "${KUBE_PS1_SYMBOL_ENABLE}" == true ]]; then
KUBE_PS1+="${KUBE_PS1_SEPARATOR}"
fi
# Context
KUBE_PS1+="$(_kube_ps1_color_fg $KUBE_PS1_CTX_COLOR)${KUBE_PS1_CONTEXT}${KUBE_PS1_RESET_COLOR}"
# Namespace
if [[ "${KUBE_PS1_NS_ENABLE}" == true ]]; then
if [[ -n "${KUBE_PS1_DIVIDER}" ]]; then
KUBE_PS1+="${KUBE_PS1_DIVIDER}"
fi
KUBE_PS1+="$(_kube_ps1_color_fg ${KUBE_PS1_NS_COLOR})${KUBE_PS1_NAMESPACE}${KUBE_PS1_RESET_COLOR}"
fi
# Suffix
[[ -n "${KUBE_PS1_SUFFIX}" ]] && KUBE_PS1+="${KUBE_PS1_SUFFIX}"
# Close Background color if defined
[[ -n "${KUBE_PS1_BG_COLOR}" ]] && KUBE_PS1+="${_KUBE_PS1_OPEN_ESC}${_KUBE_PS1_DEFAULT_BG}${_KUBE_PS1_CLOSE_ESC}"
echo "${KUBE_PS1}"
}
## end copypasta
# this is a bit messed up. This MUST return non-null. else you get N/A : N:A because the script shortcuts
get_kube_cluster() {
echo "${CYAN}k"
# if [[ "${1}" == "minikube" ]]; then
# echo "${CYAN}${1}"
# else
# echo "${RED}${1}"
# fi
}
export SHELL_WARN="false"
get_kube_ns() {
if [[ "$1" == "prod" ]]; then
SHELL_WARN="true"
echo "${RED}>>>${1}<<<${NOCOLOR}"
else
echo "${CYAN}${1}${NOCOLOR}"
fi
}
PROMPT_COMMAND=__prompt_command
__prompt_command() {
KUBE_PS1=""
if [[ "${KUBERNETES_SHELL}" == "true" ]]; then
KUBE_PS1=`kube_ps1`
else
echo ''
fi
PROMPT_LINE_COLOR=""
if [[ "${SHELL_WARN}" == "true" ]]; then
PROMPT_LINE_COLOR="${RED}"
fi
PS1="${BLUE}\u${NOCOLOR}@${YELLOW}\h:${GREEN}\w${CYAN}\`parse_git_branch\`${NOCOLOR} ${KUBE_PS1}${NOCOLOR} \\n${PROMPT_LINE_COLOR}\$ "
}
# kubernetes
alias k=kubectl
alias kcx=kubectx
alias kns=kubens
alias k_edit_secret="KUBE_EDITOR=kube-secret-editor.py kubectl edit secret"
eval "$(direnv hook bash)"
source <(kubectl completion bash)
source <(helm completion bash)
export EDITOR=emacs
export VISUAL=emacs
# android exports
#export ANDROID_EMULATOR_USE_SYSTEM_LIBS=1
export ANDROID_HOME=${HOME}/Android/Sdk
export PATH=${PATH}:${HOME}/Android/Sdk/tools/:${HOME}/Android/platform-tools/
export SPLUNK_TOKEN=0cad55ee-98e4-4225-8bf3-58d9eb910556
export SPLUNK_INDEX=bdirito-tmp
# autojump
source /usr/share/autojump/autojump.sh
# common tools bin link
export PATH=${PATH}:${HOME}/go/bin/:${HOME}/dev/tools/binlink/
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
export NODE_OPTIONS=--max-old-space-size=14096
# use local node_modules if they are there
export PATH=./node_modules/.bin/:${HOME}/.yarn/bin:${PATH}
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
eval $(thefuck --alias fk)
# python local path
export PATH=${PATH}:${HOME}/.local/bin/
alias work_shuttle='sshuttle -r [email protected]:4422 192.168.192.0/24'