-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
333 lines (289 loc) · 7.55 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
[[ $- == *i* ]] || return
# load prompt
. ~/.config/bash/prompt.sh
# set prompt
export PS1=$(ps1_prompt)
# shell - https://www.gnu.org/software/bash
if hash /usr/local/bin/bash 2>/dev/null; then
export SHELL="/usr/local/bin/bash"
else
export SHELL="/bin/bash"
fi
# bin
export PATH="$PATH:/bin"
export PATH="$PATH:/usr/bin"
export PATH="$PATH:/usr/local/bin"
export PATH="$PATH:/sbin"
export PATH="$PATH:/usr/sbin"
export PATH="$PATH:/usr/local/sbin"
export PATH="$PATH:$HOME/.cargo/bin"
# node - https://nodejs.org
export N_PREFIX="$HOME/n";
[[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin"
# go - https://golang.org/
export GOPATH="$HOME/go"
export PATH="$PATH:$GOPATH/bin"
export PATH="$PATH:/usr/local/go/bin"
export PATH="$PATH:$HOME/go/bin"
# rvm - https://rvm.io & ruby - https://www.ruby-lang.org
export PATH="$PATH:$HOME/.rvm/bin"
export PATH="$PATH:$HOME/.rvm/gems/ruby-2.3.0/bin"
export PATH="$PATH:$HOME/.rvm/gems/ruby-2.3.0@global/bin"
export RUBYOPT="$RUBYOPT:$HOME/.rvm/rubies/ruby-2.3.0/lbi/*"
# neovim - https://neovim.io
set -o vi
alias vim="nvim"
if [[ -z ${NVIM_LISTEN_ADDRESS+x} ]]; then
. ~/.config/bash/motd.sh; motd
export VISUAL="nvim"
else
# Don't nest neovim terminals
# neovim-remote - https://github.com/mhinz/neovim-remote
export VISUAL='nvr -cc split --remote-wait'
fi
export EDITOR="$VISUAL"
# std
alias c="clear"
alias l="ls -loGAh"
alias ls="ls -G"
alias la="ls -GA"
alias cls="clear; ls"
alias cla="clear; ls -A"
# git
alias glog="git tree"
alias branches="git branch -v"
alias remotes="git remote -v"
alias rebasef='git checkout master && git pull && git checkout - && git rebase master'
alias gs='git status'
alias gb='git branch -v'
alias gd='git diff'
alias gds='git diff --staged'
# fuck - https://github.com/nvbn/thefuck
eval $(thefuck --alias --enable-experimental-instant-mode)
alias FUCK='fuck'
# docker - https://www.docker.com
alias drm='docker rm $(docker ps -a -q)'
alias drmi='docker rmi $(docker images -q)'
# misc
export PATH="$PATH:$HOME/.luarocks/bin"
export PATH="$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin"
export FIGNORE="$FIGNORE:DS_Store"
# fzf - https://github.com/junegunn/fzf
export FZF_DEFAULT_COMMAND='pt -g ""'
export FZF_CTRL_T_COMMAND="${FZF_DEFAULT_COMMAND}"
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# brew - https://brew.sh/
alias brewski='brew update && brew upgrade && brew cleanup; brew doctor'
export PATH="$PATH:@@HOMEBREW_PREFIX@@/bin"
export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH"
export MANPATH="$(brew --prefix coreutils)/libexec/gnuman:$MANPATH"
# electron versioning
# export npm_config_target=1.6.11
# export npm_config_arch=x64
# export npm_config_target_arch=x64
# export npm_config_disturl=https://atom.io/download/electron
# export npm_config_runtime=electron
# export npm_config_build_from_source=true
# HOME=~/.electron-gyp npm install
# mmm wifi - https://github.com/rgcr/m-cli
wifi() {
command m wifi $@
}
# git clone
clone() {
if [[ $# -lt 1 ]]; then
echo "Usage: $0 OWNER/REPOSITORY"; return
fi
if [[ $1 =~ (git\@github.com\:)(.*)\/(.*) ]]; then
if [[ "${2}" != "" ]]; then
command git clone $1 $2
else
command git clone $1
fi
elif [[ $1 =~ .+/.+ ]]; then
if [[ "${2}" != "" ]]; then
command git clone "[email protected]:$1.git" $2
else
command git clone "[email protected]:$1.git"
fi
else
echo "Invalid format: $1"
fi
}
# git fetch and pull
fp() {
local branch="${1:-$(git rev-parse --abbrev-ref HEAD 2> /dev/null)}"
branch="${branch:-master}"
local remote="${2:-origin}"
git fetch "${remote}"
git pull "${remote}" "${branch}"
}
# git checkout
co() {
local exists=0
local branch
for branch in $(git branch --list); do
if [[ "${branch/[\*\s/|\s\s]/}" == "${1}" ]]; then
exists=1
break
fi
done
if [[ "${exists}" -eq 0 ]]; then
printf 'Branch does not exist. Would you like to create a branch named %s? [Y/n] ' ${1}
local key
read -s -n 1 key
if [[ "$key" == '' || "${key}" == 'Y' || "${key}" == 'y' ]]; then
printf '\n'
git checkout -b "${1}"
else
printf '\n'
return
fi
else
git checkout "${1}"
fi
}
# regex testing
regex() {
if [[ $# -lt 2 ]]; then
echo "Usage: regex PATTERN STRINGS..."
return
fi
regex=$1
shift
echo "regex: $regex"
echo
while [[ $1 ]]; do
if [[ $1 =~ $regex ]]; then
echo "$1 matches"
i=1
n=${#BASH_REMATCH[*]}
while [[ $i -lt $n ]]; do
echo " capture[$i]: ${BASH_REMATCH[$i]}"
let i++
done
else
echo "$1 does not match"
fi
shift
done
}
# quick linting with standard/snazzy
lint() {
if [[ $@ == "fix" ]]; then
command standard --fix | snazzy
elif [[ -z "${1}" ]]; then
command standard --verbose | snazzy
else
command standard "${1}"
fi
}
# launchctl/kwm reload
load() {
if [[ $@ == "kwm" ]]; then
if [[ -f ~/Library/LaunchAgents/com.koekeishiya.kwm.plist ]]; then
command launchctl load ~/Library/LaunchAgents/com.koekeishiya.kwm.plist
else
command brew services start koekeishiya/formulae/kwm
fi
else
command launchctl load "$@"
fi
}
unload() {
if [[ $@ == "kwm" ]]; then
if [[ -f ~/Library/LaunchAgents/com.koekeishiya.kwm.plist ]]; then
command launchctl unload ~/Library/LaunchAgents/com.koekeishiya.kwm.plist
else
command brew services stop koekeishiya/formulae/kwm
fi
else
command launchctl unload "$@"
fi
}
# beertime ?
beertime() {
curl http://beero.cl/ock
}
# Go set path
gosp() {
export OLD_GOPATH=$GOPATH
export OLD_GOBIN=$GOBIN
if [[ "${1}" == "revert" ]]; then
export GOPATH=$OLD_GOPATH
export GOBIN=$OLD_GOBIN
else
export GOPATH=$(pwd);
export GOBIN="$(pwd)/bin"
fi
export PATH="$PATH:$GOBIN;"
}
resolve() {
if [[ "${1}" == "" ]]; then
echo "you must pass a domain."
fi
echo "RESOLVING DOMAIN: $1"
echo "----------------------------------------------------------------------"
echo "RECORDS..."
dig $1
echo "----------------------------------------------------------------------"
echo "TRACING NAMESERVERS..."
dig NS $1 +trace
echo "----------------------------------------------------------------------"
echo "GET request"
curl -# --verbose -X GET $1 -o /dev/null
}
h() {
if [[ "${#@}" -eq 0 ]]; then
history
else
history | grep "${@}" | head -n $(($(history | grep ${@} | wc -l) - 1))
fi
}
s() {
local results=
results=$(grep --exclude-dir=node_modules -rnw "${PWD}" -e "${1}")
echo -e "${results}"
printf "Total Results: $(echo "${results}" | wc -l)\n"
}
todo() {
grep \
--exclude-dir=node_modules \
--exclude-dir=build \
--exclude-dir=public \
--exclude-dir=.git \
--text \
-nRo ' TODO.*' .
}
fr() {
local excludes=
local fType=
fType="${2}"
if [[ -f '.gitignore' ]]; then
for file in $(cat .gitignore); do
if [[ -f "${file}" ]]; then
excludes+=" ! -wholename '*${file}'"
elif [[ -d "${file}" ]]; then
excludes+=" ! -wholename './${file/\//}/*'"
fi
done
fi
if [[ "${fType}" == "" ]]; then
fType="'*'"
fi
echo "find . -type f -name ${fType}${excludes} -exec sed -i '${1}' {} +"
find . -type f -name ${fType}${excludes} -exec sed -i '${1}' {} +
}
# gpg commit signing
export GPG_TTY=`tty`
if [ "$PS1" ]; then
unset GPG_AGENT_INFO
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="${HOME}/.gnupg/S.gpg-agent.ssh"
fi
fi
# bash completion
for file in /usr/local/etc/bash_completion.d/*; do
source $file
done