-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_bashrc
370 lines (295 loc) · 10.1 KB
/
dot_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
##############
## KROW ##
##############
test -f ${HOME}/.krow.rc && source ${HOME}/.krow.rc
##############
## Common ##
##############
#export GOPATH=$HOME/golang
# Autocompletes
# [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
[[ -r "/opt/homebrew/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/etc/profile.d/bash_completion.sh"
# curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
source ~/.git-completion.bash
# swift
## swift package completion-tool generate-bash-script > ~/.swift-package-complete.bash
source ~/.swift-package-complete.bash
# pip
## pip completion --bash >> ~/.pip-complete.bash
source ~/.pip-complete.bash
# poetry
## poetry completions bash > .poetry.bash-completion
source ~/.poetry.bash-completion
# tmux
[ -f /opt/homebrew/etc/bash_completion.d/tmux ] && . /opt/homebrew/etc/bash_completion.d/tmux
# brew
[ -f /opt/homebrew/etc/bash_completion.d/brew ] && . /opt/homebrew/etc/bash_completion.d/brew
# disable the bash session mumbo jumbo and use one history file, also
## touch ~/.bash_sessions_disable
export SHELL_SESSION_HISTORY=0
# BASH History
export HISTSIZE=1000000
export HISTFILESIZE=2000000
export HISTCONTROL=ignoredups:ignorespace
shopt -s histappend
export PROMPT_COMMAND=log_history
alias his="history -n; history -a"
shopt -s checkwinsize
#export PYTHONSTARTUP=~/.pythonrc
# pipenv
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export PIPENV_VENV_IN_PROJECT=1
export VENVS_PATH=${HOME}/.virtualenvs
# brew
alias brew86="arch -x86_64 /usr/local/homebrew/bin/brew"
# arm brew
#export HOMEBREW_PREFIX_86=/usr/local
export HOMEBREW_PREFIX="/opt/homebrew"
export HOMEBREW_CELLAR="/opt/homebrew/Cellar"
export HOMEBREW_REPOSITORY="/opt/homebrew"
export HOMEBREW_SHELLENV_PREFIX="/opt/homebrew"
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:"
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}"
#eval "$(/opt/homebrew/bin/brew shellenv)"
############
## Path ##
############
# openssl
SSL_PATH="${HOMEBREW_PREFIX}/opt/openssl/bin/"
export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/opt/[email protected]/lib/pkgconfig"
# x86
SSL_PATH_86="/usr/local/opt/openssl/bin"
export PKG_CONFIG_PATH_86="/usr/local/opt/[email protected]/lib/pkgconfig"
LLVM_PATH=/usr/local/opt/llvm/bin/
# Set PATH
export PATH=${POETRY_PATH}:${PATH}
export PATH=${SSL_PATH}:${PATH}
export PATH=${LLVM_PATH}:${PATH}
export PATH=$HOME/.bin:${HOMEBREW_PREFIX}/bin:${HOMEBREW_PREFIX}/lib:${HOMEBREW_PREFIX}/sbin:${HOMEBREW_PREFIX}/include:${PATH}
#############
## Alias ##
#############
## setup prompt
export PS1="\[\033[38;5;208m\][\[$(tput sgr0)\]\[\033[38;5;136m\]\W\[$(tput sgr0)\]\[\033[38;5;208m\]]\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;228m\]⤳ \[$(tput sgr0)\] \[$(tput sgr0)\]"
alias PS1_kw="\[\033[38;5;228m\]\h\[$(tput sgr0)\]:\[$(tput sgr0)\]\[\033[38;5;184m\][\[$(tput sgr0)\]\[\033[38;5;100m\]\W\[$(tput sgr0)\]\[\033[38;5;184m\]]\[$(tput sgr0)\] \[$(tput sgr0)\]\[\033[38;5;228m\]> \[$(tput sgr0)\] \[$(tput sgr0)\]"
alias PS1_old='\[$(tput setaf 11)\][\[$(tput setaf 137)\]\W\[$(tput setaf 11)\]] ⤳ \[$(tput sgr0)\]'
alias hPS="PS1='\[\033[01;30m\]\h\[\033[00m\]:[\[\033[01;37m\]\W\[\033[00m\]] ⤳ '"
alias sPS="PS1='[\[\033[01;33m\]\u@\h\[\033[00m\]]:\[\033[01;31m\]\W\[\033[00m\]\⤳ '"
alias lPS="PS1='[\[\033[01;31m\]\w\[\033[00m\]]⤳ '"
alias reload="source ~/.bashrc"
alias tsaver='j=0;a=1;x=1;y=1;xd=1;yd=1;while true;do for i in {1..2000} ; do if [[ $x == $LINES || $x == 0 ]]; then xd=$(( $xd *-1 )) ; fi ; if [[ $y == $COLUMNS || $y == 0 ]]; then yd=$(( $yd * -1 )) ; fi ; x=$(( $x + $xd )); y=$(( $y + $yd )); printf "\33[%s;%sH\33[48;5;%sm . \33[0m" $x $y $(( $a % 8 + 16 + $j % 223 )) ;a=$(( $a + 1 )) ; done ; x=$(( x%$COLUMNS + 1 )) ; j=$(( $j + 8 )) ;done'
alias t="tmux"
alias d="deactivate"
export EDITOR='emacs'
alias e='emacs'
alias ec='emacsclient'
alias editrc='e ~/.bashrc'
alias editgit='e ~/.gitconfig'
alias editemacs='e ~/.emacs'
alias ssh='ssh -o TCPKeepAlive=yes -o ServerAliveInterval=4'
alias p='cd -'
alias b='cd ..'
alias bb='cd ../..'
alias bbb='cd ../../..'
alias bbbb='cd ../../../..'
# GIT
alias gitp='git --no-pager'
# docker
alias docker-clean-images='docker rmi $(docker images -a --filter=dangling=true -q)'
alias docker-clean-ps='docker rm $(docker ps --filter=status=exited --filter=status=created -q)'
alias docker-clean-cache='docker rmi $(docker images -a -q)'
alias docker-build-dev='docker build -t $(echo "$(basename $(pwd))-dev") .'
# start OSX screensaver
alias ssaver="open -b com.apple.ScreenSaver.Engine"
alias open-ports="sudo lsof -iTCP -sTCP:LISTEN -n -P"
alias df='df -h'
alias du='du -h'
# ls
alias ls='ls --color=always'
alias ll='ls -lFh --color=always'
alias la='ls -Ah --color=always'
alias lad='la -d */'
alias l='ls -A1F --color=always'
alias lt='ll -t --color=always'
alias lh='ls -Ap --color=always | egrep "^\..*/$"' # hidden dirs only
alias tree='tree -C'
alias list-venvs='ls ${VENVS_PATH}'
function log_history () {
history -a
# https://spin.atomicobject.com/2016/05/28/log-bash-history/
if [ "$(id -u)" -ne 0 ]; then
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs-bash/bash-history-$(date "+%Y-%m-%d").log
fi
}
function forever {
local cmd=${@}
echo "**forever** '${cmd}'"
while true; do eval ${cmd}; done
}
function repeat_5 {
local cmd=${@}
local times=5
for i in $(seq ${times}); do eval '${cmd}'; sleep 1; done
}
function repeat {
local cmd=${@}
while true; do eval '${cmd}'; sleep 1; done
}
function py-elpy-requirements {
pip3 install --force-reinstall jedi autopep8 rope flake8 black yapf
}
function py-ipython-reqs {
# python3.6 requires rlipython==0.1.1
pip3 install --force-reinstall ipython==6.5.0 rlipython==0.1.1 gnureadline
}
function py-lint-reqs {
pip3 install --force-reinstall pycodestyle flake8 mypy
}
function load-glob-pyvenv {
local py_version=${1}
if [ -z "${py_version}" ]; then
py_version="py_38"
fi
if [ -d "${VENVS_PATH}/${py_version}" ]; then
source "${VENVS_PATH}/${py_version}/bin/activate"
fi
}
function a {
source "${1}bin/activate"
}
function install-reqs {
if [ -f requirements.txt ]; then
pip3 install -r requirements.txt
fi
}
function py-run-checks {
local against="${@:1}"
echo "** Running pycodestyle ${against} **"
pycodestyle ${against}
echo "** Running flake8 ${against} **"
flake8 ${against}
echo "** Running mypy ${against} **"
mypy ${against}
}
function ls-dirs {
local path=$1
if [ -z ${path} ]; then
path="*/"
else
path+="*/"
fi
ls -d ${path}
}
# find
function find_d {
if [ $# -gt 1 ]; then
find $2 -type d -iname $1
else
find . -type d -iname $1
fi
}
function find_f {
if [ $# -gt 1 ]; then
find $2 -iname "$1"
else
find . -iname "$1"
fi
}
# find_fr usage: regex (find options e.g. print0 -xargs ..)
# e.g. find_fr ".*\.cs" -print0
function find_fr {
echo searching: $1
echo find_options: ${@:2:($#)}
echo "-----------------------------------------"
find . -iregex "$1" ${@:2:($#)}
}
## find_fg usage: filePattern (location) grepPattern
function find_fg {
echo searching: ${@:1:($#-1)}
echo grepping: ${@:($#)}
echo "-----------------------------------------"
find_fr ${@:1:($#-1)} -exec /usr/bin/grep -nri --color=auto "${@:($#)}" {} \;
}
## find and pass it to other command
## find_fa usage: find_fa "some_file.cpp" "git logp"
function find_fa {
if [ ! $# -gt 1 ]; then
echo "find_fa: too few args '$*' passed."
return -1
fi
echo "Finding files matching: '${@:1:($#-1)}' and passing to command '${@:($#)}'"
find_f "${@:1:($#-1)}" | xargs -n1 ${@:($#)}
}
function treetree {
SEDMAGIC='s;[^/]*/;|____;g;s;____|; |;g'
if [ "$#" -gt 0 ] ; then
dirlist="$@"
else
dirlist="."
fi
for x in $dirlist; do
find "$x" -print | sed -e "$SEDMAGIC"
done
}
alias treeish=treeish
function treeish {
if [ "$1" != "" ]
then
cd "$1"
fi
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ] # check if no folders
then
echo " -> no sub-directories"
fi
cd - > /dev/null 1>&1
}
function git_author_stats {
author=$1
git log --author="${author}" --pretty=tformat: --numstat \
| gawk "{ add += \$1 ; subs += \$2 ; loc += \$1 - \$2 } END { printf \"Author: ${author} added lines: %s removed lines: %s total lines: %s\n\",add,subs,loc }" -
}
############
## Grep ##
############
alias g="grep -i --color=auto"
alias gr="grep -ir --color=auto"
alias gv="grep -v -i --color=auto"
alias gn="grep -nH -i --color=auto"
alias xg="xargs -n1"
######################
## Man-pages|less ##
######################
# lesspipe stopped showing colors in terminal, use pygments instead
#export LESSQUIET=1
#export LESSOPEN="| /opt/homebrew/bin/lesspipe.sh %s" LESS_ADVANCED_PREPROCESSOR=1
#export LESSOPEN="| ~/.lesscolor %s"
export LESSOPEN="|/opt/homebrew/bin/lesspipe.sh %s"
export LESSCOLORIZER="source-highlight"
export LESS_ADVANCED_PREPROCESSOR=1
export LESS='-R -i -X'
alias lessl='less -N'
#man pages with color.
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
# #less with colours:
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# bash magic to call functions defined here
# e.g. source ~/.bashrc activate_venv
#"$@"