-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
366 lines (283 loc) · 10.4 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
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# Bash Completion
# ===============
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# sudo completion
complete -cf sudo
if [ -e "$HOME/.git-completion.bash" ]; then
source "$HOME/.git-completion.bash"
fi
# Include custom
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH
export PATH=/usr/local/heroku/bin:$PATH
# PATH modifications
# ==================
if [ -d ~/bin ] ; then
PATH=~/bin:"${PATH}"
fi
if [ -d ~/.local/bin ] ; then
PATH=~/.local/bin:"${PATH}"
fi
# Support for local ruby gems
RUBY_GEM=$(ruby -e "puts Gem.user_dir")/bin
if [ -d $RUBY_GEM ]; then
PATH=$RUBY_GEM:"${PATH}"
fi
alias subl="subl -n ."
export PATH=/usr/bin/site_perl/:$PATH
export ANDROID_SDK_ROOT=/opt/android-sdk
export PATH=$ANDROID_NDK_ROOT:$ANDROID_SDK_ROOT:$PATH
export ANDROID_HOME=$ANDROID_SDK_ROOT
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
if [ -d ${HOME}/Projects/homebrew ]; then
export PATH=${HOME}/Projects/homebrew/bin:${PATH}
fi
export PATH=$(npm bin):$PATH
export PATH=$PATH:/usr/lib/node_modules/.bin/
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
if [ -d ${HOME}/.cargo/bin ]; then
export PATH=${HOME}/.cargo/bin:${PATH}
fi
# Global environment definitions
# ==============================
# History control
# --------------
unset HISTFILESIZE
export HISTCONTROL=ignoredups # Ignore duplicate entries in history
export HISTSIZE=1000000
export HISTFILESIZE=1000000
export HISTIGNORE="&:ls:ll:la:l.:pwd:exit:clear:clr:[bf]g"
shopt -s histappend # Append history instead of overwriting
shopt -s cdspell # Correct minor spelling errors in cd command
shopt -s dotglob # includes dotfiles in pathname expansion
shopt -s checkwinsize # If window size changes, redraw contents
shopt -s cmdhist # Multiline commands are a single command in history.
shopt -s extglob # Allows basic regexps in bash.
export EDITOR="vim"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# Typing EOF (ctrl+d) will not exit interactive sessions
set ignoreeof on
export IGNOREEOF=1
export PYTHONDONTWRITEBYTECODE=1
export LESS=FRSX
export WINEARCH=win32
# Alias definitions
# -----------------
alias acka='ag -a'
alias aga='ag -a'
alias cdpr='cd ~/Projects'
# convert permissions to octal - http://www.shell-fu.org/lister.php?id=205
alias lo='ls -l | sed -e 's/--x/1/g' -e 's/-w-/2/g' -e 's/-wx/3/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/rwx/7/g' -e 's/---/0/g''
# get an ordered list of subdirectory sizes
alias dux='du -skh ./* | sort -h | grep -v total && du -cskh ./* | grep total'
if [ "$(uname)" == "Darwin" ]; then
alias ls='ls -GF'
else
alias ls='ls -F --color'
fi
alias ..='cd ..' # Go up one directory
alias ...='cd ../..' # Go up two directories
alias l='ls -lah' # Long view, show hidden
alias la='ls -AF' # Compact view, show hidden
alias ll='ls -lFh' # Long view, no hidden
# Helpers
alias grep='grep' # Always highlight grep search term
#alias ping='ping -c 5' # Pings with 5 packets, not unlimited
alias df='df -h' # Disk free, in gigabytes, not bytes
alias du='du -h -c' # Calculate total disk usage for a folder
# Nifty extras
alias clr='clear;echo "Currently logged in on $(tty), as $(whoami) in directory $(pwd)."'
alias pycclean='find . -name "*.pyc" -exec rm {} \;'
alias xo='xdg-open'
alias wtc="curl --silent 'http://whatthecommit.com/index.txt'"
# "last as root"
alias lr='su -c "$(history | tail -n 2 | head -n 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")"'
alias grep='grep'
alias fgrep='fgrep'
alias egrep='egrep'
alias ll='ls -halG'
alias ipy='python -c "import IPython; IPython.embed()"'
alias jpp='python -mjson.tool'
alias git='hub'
alias submod='subl $(git diff --name-only)'
# Git related shortcuts
alias gst='git st'
alias gci='git ci'
alias gco='git co'
alias gpu='git pu'
alias gbr='git br'
alias gdi='git diff'
# bash function to decompress archives - http://www.shell-fu.org/lister.php?id=375
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1;;
*.tar.gz) tar xvzf $1;;
*.bz2) bunzip2 $1;;
*.rar) unrar x $1;;
*.gz) gunzip $1;;
*.tar) tar xvf $1;;
*.tbz2) tar xvjf $1;;
*.tgz) tar xvzf $1;;
*.zip) unzip $1;;
*.Z) uncompress $1;;
*.7z) 7za x $1;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# open up the bitbucket page for the current repository
bb() {
local P="$(hg paths 2>/dev/null | grep 'bitbucket.org' | head -1)"
local URL="$(echo $P | sed -e's|.*\(bitbucket.org.*\)|http://\1|')"
[[ -n $URL ]] && firefox $URL || echo "No Bitbucket path found!"
}
# open up the github page for the current repository
gg() {
local P="$(git remote -v 2>/dev/null | grep 'github.com' | head -1)"
local URL="$(echo $P | sed -e's|.*\(github.com.*\)|http://\1|' | sed -e 's| (fetch)||' | sed -e 's|.com:|.com\/|' | sed -e 's|.git$||')"
[[ -n $URL ]] && firefox $URL || echo "No GitHub path found!"
}
exip () {
# gather external ip address
echo -n "Current External IP: "
curl -s -m 5 http://ipecho.net/plain
echo
}
lsmod() {
{
echo "Module Size Ref UsedBy Stat Address"
cat /proc/modules
} | column -t
}
# Virtual Python Environment, VCS and Fancy Promt
# ===============================================
_vcprompt () {
if [ "$VIRTUAL_ENV" ]; then
out=$(vcprompt -f "[%n:%b%m ($(basename $VIRTUAL_ENV))] ")
else
out=$(vcprompt -f "[%n:%b%m] ")
fi
if [ "$out" == "" ]; then
[[ -n "$VIRTUAL_ENV" ]] && echo "($(basename $VIRTUAL_ENV)) " || echo ""
else
echo "$out"
fi
}
# Automatic virtualenv activation based on .venv config file with
# hook integration.
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
export WORKON_HOME=$HOME/.virtualenvs
[ -r /usr/bin/virtualenvwrapper_lazy.sh ] && . /usr/bin/virtualenvwrapper_lazy.sh
[ -r /usr/local/bin/virtualenvwrapper_lazy.sh ] && . /usr/local/bin/virtualenvwrapper_lazy.sh
# For OSX with local homebrew
[ -r ~/Projects/homebrew/bin/virtualenvwrapper_lazy.sh ] && . ~/Projects/homebrew/bin/virtualenvwrapper_lazy.sh
export VIRTUAL_ENV_DISABLE_PROMPT=1
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_REQUIRE_VIRTUALENV=true
export PIP_RESPECT_VIRTUALENV=true
# Python development
export PYTHONSTARTUP="$HOME/.pythonrc.py"
# Automatically a Projects virtual environments based on the
# directory name of the project. Virtual environment name will be identified
# by placing a .venv file in the project root with a virtualenv name in it.
# If a .venv_hook file exists it gets sourced.
function workon_cwd {
if [ $? == 0 ]; then
# Find the repo root and check for virtualenv name override
PROJECT_ROOT=$(pwd)
ENV_NAME="$(basename $(pwd))"
if [ -f "$PROJECT_ROOT/.venv" ]; then
ENV_NAME=`cat "$PROJECT_ROOT/.venv"`
fi
# Activate the environment only if it is not already active
if [ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]; then
if [ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]; then
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
MANAGE_PY=$(find "$PROJECT_ROOT" -not -path '(*tox*|*.git*)' -name 'manage.py' -type f -print | head -n 1)
if [ -e "$MANAGE_PY" ]
then
alias django="python $MANAGE_PY"
else
[ -n "`alias -p | grep '^alias django='`" ] && unalias django
fi
fi
if [ -d "$PROJECT_ROOT/node_modules" ]; then
export NODE_MODULES="$PROJECT_ROOT/node_modules"
export PATH=$PROJECT_ROOT/node_modules/.bin:$PATH
fi
fi
if [ -f "$PROJECT_ROOT/.venv_hook" ]; then
source "$PROJECT_ROOT/.venv_hook"
fi
elif [ $CD_VIRTUAL_ENV ]; then
# We've just left the repo, deactivate the environment
# Note: this only happens if the virtualenv was activated automatically
deactivate && unset CD_VIRTUAL_ENV
[ -n "`alias -p | grep '^alias django='`" ] && unalias django
fi
}
# New cd function that does the virtualenv magic
function venv_cd {
cd "$@" && workon_cwd
history -a
}
alias cd="venv_cd"
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
from() { expect -c "spawn -noecho python
expect \">>> \"
send \"from $*\r\"
interact +++ return"; }
import() { expect -c "spawn -noecho python
expect \">>> \"
send \"import $*\r\"
interact +++ return";
}
# Export the promt with advanced vcs information
export PS1='\[\e[33;1m\]$(_vcprompt)\[\e[0m\]\[\e[32;1m\]\w> \[\e[0m\]'
# integrate with ksshaskpass
if [ -f "/usr/bin/ksshaskpass" ]; then
export SSH_ASKPASS="/usr/bin/ksshaskpass"
fi
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
if ! pgrep -u $USER ssh-agent > /dev/null; then
ssh-agent > ~/.ssh-agent-thing
fi
if [[ "$SSH_AGENT_PID" == "" ]]; then
eval $(<~/.ssh-agent-thing)
fi
ssh-add -l >/dev/null || alias ssh='ssh-add -l >/dev/null || ssh-add && unalias ssh; ssh'
export SPIDERMONKEY_INSTALLATION=~/.spidermonkey
gifify() {
if [[ -n "$1" ]]; then
ffmpeg -i $1 -r 20 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - >! $1.gif
rm -f out-static*.png
else
echo "proper usage: gifify <input_movie.mov>. You DO need to include extension."
fi
}
onmn() {
echo "Next migration-number: $(ls src/olympia/migrations/ | cut -d '-' -f 1 | sort -rn | awk '{printf "%03d", $1 + 1; exit}')"
}
export PATH="/usr/local/sbin:$PATH"
# added by travis gem
[ -f /home/chris/.travis/travis.sh ] && source /home/chris/.travis/travis.sh
# source /usr/share/nvm/init-nvm.sh
export GOPATH=$HOME/.go
export PATH="$PATH:$GOPATH/bin" # Ditto.
export PATH="$HOME/.cargo/bin:$PATH"
source /usr/share/nvm/init-nvm.sh
export B2_ACCOUNT_ID=001e3682bee50b70000000001
export B2_ACCOUNT_KEY=K001XjGYEx14aoewSbL2z4hXGClfba4