forked from johnandersen777/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pdxjohnnyrc
318 lines (265 loc) · 8.18 KB
/
.pdxjohnnyrc
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
#!/bin/bash
#
# ~/.pdxjohnnyrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# History config
unset HISTFILESIZE
export HISTSIZE=1000000
export HISTFILESIZE=1000000
shopt -s histappend
export PROMPT_COMMAND='history -a'
export HISTCONTROL=ignoredups
alias gitl="git log --graph --topo-order --decorate --oneline --all"
# Fixes font issues
export XDG_CONFIG_HOME="${HOME}/.config"
# Fixes autotools "possibly undefined macro" and "please use m4_pattern_allow"
export ACLOCAL_FLAGS='-I /usr/local/share/aclocal'
export PKG_CONFIG_PATH='/usr/local/lib/pkgconfig'
# Prompt config
# export PS1='[\u@\h \W]\$ '
if [ "$USER" == "johnsa1" ]; then
export PS1='\[\033[01;34m\]$(date)\[\033[00m\] \[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\] \$ '
else
# From Solus Linux
endchar="\$"
FG="\[\033[38;5;081m\]"
BG="\[\033[38;5;245m\]"
AT="\[\033[38;5;245m\]"
HCOLOR="\[\033[38;5;206m\]"
export PS1="${FG}\u${AT}@${HCOLOR}\H ${BG}\W ${FG}$endchar \[\e[0m\]"
fi
export PS1="; "
export PS1="$ "
# Grep colors
alias grep='grep --color=auto'
alias ag='grep --color=always -Hrn'
alias ll='ls -lAF'
# New Virtualenv
nvenv () {
python3 -m virtualenv $@ .venv
source .venv/bin/activate
}
# Make and valgrind through less
makel () {
make "$@" 2>&1 | less -r
}
valgrindl () {
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes "$@" \
2>&1 | less -r
}
# Anything throgh less
lessit () {
"$@" 2>&1 | less -r
}
tmpd () {
mkdir -p ~/.tmp
cd "$(mktemp -p ~/.tmp -d)"
}
alias youtube-dl="python3.7 -m youtube_dl --no-call-home --no-cache-dir -x --audio-format mp3 --add-metadata --audio-quality 0 --restrict-filenames --yes-playlist --ignore-errors"
alias ssh_proxy="ssh -nNT -D 9050"
# Add ll
alias ls='ls --color=auto'
alias ll='ls -lAF'
function lll () {
ls --color=always -lAF $@ | less -r
}
# VPN like proxy through ssh
alias vpn="sshuttle --dns -r $VPN_SERVER 0/0"
# Lynx config
export WWW_HOME="https://google.com"
alias lynx="lynx -accept_all_cookies -cookie_file=$HOME/.lynx_cookies"
# Set editor to vim
export EDITOR=vim
# GPG password in terminal
export GPG_TTY=$(tty)
# Go config
export GOPATH="${HOME}/Documents/go"
# export GOROOT="${HOME}/.local/go"
export GOBIN="${GOPATH}/bin"
alias goh="cd ${GOPATH}/src/github.com/pdxjohnny"
if [ -d $GOBIN ]; then
export PATH="$PATH:$GOBIN"
fi
# bin config
export PDXJOHNNY_BIN="${HOME}/.bin"
if [ -d "$PDXJOHNNY_BIN" ]; then
export PATH="$PATH:$PDXJOHNNY_BIN"
fi
# Term broadcast
gottyb () {
gotty tmux attach -t `tmux display -p '0'`
}
# Virtualenv
venv () {
__venv="$HOME/Documents/python/.venv"
if [ ! -f "$__venv/bin/activate" ]; then
mkdir -p "$HOME/Documents/python"
virtualenv -p python3 "$__venv"
fi
source "$__venv/bin/activate"
}
# Tensorflow Virtualenv
tf () {
if [ ! -f "$HOME/.tensorflow/bin/activate" ]; then
virtualenv --system-site-packages -p python3 "$HOME/.tensorflow"
source "$HOME/.tensorflow/bin/activate"
pip install --upgrade tensorflow
else
source "$HOME/.tensorflow/bin/activate"
fi
}
# IPython Notebook
notebook () {
venv
if [ ! -d "$HOME/Documents/python/notebook" ]; then
mkdir -p "$HOME/Documents/python/notebook"
fi
cd "$HOME/Documents/python/notebook"
jupyter notebook
}
spotify() {
docker run -it \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=unix$DISPLAY \
--device /dev/snd \
--name spotify \
jess/spotify
}
install_minikube() {
tmpd
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl
export MINIKUBE_WANTUPDATENOTIFICATION=false
export MINIKUBE_WANTREPORTERRORPROMPT=false
export MINIKUBE_HOME=$HOME
export CHANGE_MINIKUBE_NONE_USER=true
mkdir $HOME/.kube || true
touch $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
./minikube start --vm-driver=none
# this for loop waits until kubectl can access the api server that Minikube has created
for i in {1..150}; do # timeout for 5 minutes
./kubectl get po &> /dev/null
if [ $? -ne 1 ]; then
break
fi
sleep 2
done
echo "kubectl commands are now able to interact with Minikube cluster"
}
# Android config
export ANDROID_HOME="${HOME}/Android/Sdk"
# For clang-format
alias clang-format="clang-format -i -style=llvm"
alias youtube-dl="youtube-dl --no-call-home --no-cache-dir -x --audio-format mp3 --add-metadata --audio-quality 0 --restrict-filenames --yes-playlist --ignore-errors"
# For mbed
if [ -f "/bin/arm-none-eabi-gcc" ]; then
export GCC_ARM_PATH="/bin"
fi
function killssh () {
kill $(ps aux | grep ssh | grep \@pts | awk '{print $2}')
}
function unloop_image {
if [ -b ${LOOP} ]; then
sudo losetup -d ${LOOP}
LOOP='/dev/non-existant'
fi
}
function loop_image {
IMAGE="${1}"
export LOOP=$(sudo losetup --find --show ${IMAGE})
trap unloop_image EXIT
}
function unmount_image {
if [ -d ${TMP_MNT_DIR} ]; then
if [ "x${PWD}" == "x${TMP_MNT_DIR}" ]; then
cd '/tmp'
fi
# Unmount image
export again=1
while [ "$again" -eq 1 ]; do
# Unmount image
sudo sync
( sudo umount -d -R "${TMP_MNT_DIR}" && \
rm -rf "${TMP_MNT_DIR}" ) \
&& export again=0 \
|| \
export again=1
done
rm -rf ${TMP_MNT_DIR}
fi
unloop_image
}
function mount_image() {
export TMP_MNT_DIR=$(mktemp -d)
sudo partx -a ${LOOP}
sudo mount -o rw ${LOOP}p3 ${TMP_MNT_DIR} || (
SIZE=$(sudo fdisk -l ${LOOP} | grep Units: | awk '{print $(NF-1)}')
START=$(sudo fdisk -l ${LOOP} | grep 'Linux root' | awk '{print $2}')
OFFSET=$((SIZE * START))
sudo mount -o loop,rw,offset=${OFFSET} ${LOOP} ${TMP_MNT_DIR}
)
trap unmount_image EXIT
}
function randstr() {
python3 -c 'import os, hashlib; print(hashlib.sha384(os.urandom(int(4096 / 8))).hexdigest())'
}
# Add to path
# if which ruby >/dev/null && which gem >/dev/null; then
# export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
#fi
if [ -f "$HOME/.cargo/env" ]; then
source $HOME/.cargo/env
fi
# Add to path
# if which ruby >/dev/null && which gem >/dev/null; then
# export PATH="$(ruby -rubygems -e 'puts Gem.user_dir')/bin:$PATH"
# fi
ADD_PATH=("${HOME}/.local/bin" \
"${ANDROID_HOME}/platform-tools" \
"/usr/local/go/bin" \
"${HOME}/.local/node_modules/.bin" \
"${HOME}/.local/usr/lib/npm-packages/bin" \
"${GOBIN}" \
"${HOME}/Documents/flutter/flutter/bin" \
"${HOME}/Documents/flutter/flutter/bin/cache/dart-sdk/bin" \
"${HOME}/.pub-cache/bin" \
"${HOME}/.gem/ruby/2.6.0/bin" \
"${HOME}/.pyenv/versions/3.7.2/bin/" \
"${HOME}/.yarn/bin" \
"${HOME}/.cargo/bin" \
"${HOME}/.deno/bin")
for CURR in ${ADD_PATH[@]}; do
if [ -d $CURR ]; then
export PATH="$CURR:$PATH"
fi
done
# For asciinema https://github.com/asciinema/asciinema/issues/206
export LC_ALL=${LANG}
# For react scripts
export BROWSER=none
export REACT_EDITOR=none
# For alice
alias herstory='history'
# Quick re-exec of bash, useful for re-tmuxing to asciinema
alias b='exec bash'
# Homedir venv
if [ -f "${HOME}/.local/.venv/bin/activate" ]; then
. "${HOME}/.local/.venv/bin/activate"
fi
# Source all the files that need to be sourced
for file in $(ls -a ${HOME} | grep '_source'); do
source "${HOME}/$file"
done
if [ -f "${HOME}/.cargo/env" ]; then
source "${HOME}/.cargo/env"
fi
export NO_PROXY="$(OIFS="$IFS"; IFS=$'\n'; array=($(ip a | grep inet\ | awk '{print $2}' | sed -e 's/\/.*//g' | sort | uniq)); IFS="$OIFS"; array+=(${NO_PROXY}); (export IFS=','; echo "${array[*]}"))"
export no_proxy="$(OIFS="$IFS"; IFS=$'\n'; array=($(ip a | grep inet\ | awk '{print $2}' | sed -e 's/\/.*//g' | sort | uniq)); IFS="$OIFS"; array+=(${no_proxy}); (export IFS=','; echo "${array[*]}"))"
function git_grep_and_edit {
local FILE=$(git grep -n "$@" | sed -e 's/:.*//g' | head -n ${RESULT_NUM:-1} | tail -n 1);
local LINE_NO=$(git grep -n "$@" | sed -e 's/:/__HELPER_LINENO_REPLACE__/2' | sed -e 's/__HELPER_LINENO_REPLACE__.*//g' -e 's/.*://g' | head -n ${RESULT_NUM:-1} | tail -n 1);
vim "+${LINE_NO}" "${FILE}";
}