-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
447 lines (388 loc) · 11.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
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
# -----------
# General
# -----------
alias ra='rake'
alias ..='cd ..'
alias cp='cp -R'
alias m.='mate .'
alias ll='ls -lh'
alias la='ls -la'
alias du='du -hc'
alias more='less'
alias 64='base64'
alias psa='ps -Ax'
alias cd..='cd ..'
alias cl='clear;ls'
alias rrrm='rm -rf'
alias err='echo $?'
alias get='curl -L'
alias pine='alpine'
alias sch='scheme48'
alias scm='scheme48'
alias chx='chmod +x'
alias xo='xargs open'
alias ldir='ls -d */'
alias ....='cd ../../'
alias mkdir='mkdir -p'
alias af='find . | ack'
alias beep="echo $'\a'"
alias base64='base64 --quiet'
alias recent='ls -lAt | head'
alias gsed='/usr/local/bin/sed'
alias bashhelp='cat ~/.bashhelp'
alias today='date +"%A, %B %d, %Y"'
alias yest='date -v-1d +"%A %B %d, %Y"'
alias now='ruby -e "puts Time.now.to_i"'
alias junit='java junit.textui.TestRunner'
alias htdocs='cd /Applications/MAMP/htdocs/'
alias prepare-ChangeLog='prepare-ChangeLog -o'
alias po='pomo' # http://github.com/visionmedia/pomo
alias ql='qlmanage -p "$@" >& /dev/null' # Quick Look alias
alias mampmysql='/Applications/MAMP/Library/bin/mysql -u joe -p'
alias matedir='cd ~/Library/Application\ Support/TextMate/Bundles'
alias crongen="whenever --load-file ~/.whenever --update-crontab joe"
alias webserver="echo 'http://bogojoker.is-a-geek.com:8000/'; python -m SimpleHTTPServer"
alias desktoptopia='open /Users/joe/Library/Application\ Support/Desktoptopia/.Backgrounds/'
# --------------------
# Global Variables
# --------------------
bin="$HOME/bin"
code="$HOME/code"
rit="/Volumes/RIT/"
hask="$HOME/haskell"
cron="$bin/crontasks/"
webkit="$HOME/WebKit"
desktop="$HOME/Desktop"
webcore="$webkit/WebCore"
patch="$HOME/Desktop/patch"
jsc="$webkit/JavaScriptCore"
layout="$webkit/LayoutTests/"
school="$HOME/Desktop/School/"
inspector="$webcore/inspector"
frontend="$inspector/front-end"
htdocs="/Applications/MAMP/htdocs"
bogo="/Volumes/BogoJoker/public_html"
# ------------------
# Mini Variables
# ------------------
b="$bogo"
c="$code"
p="$patch"
h="$htdocs"
w="$webkit"
d="$desktop"
lt="$layout"
wc="$webcore"
f="$frontend"
# -------------
# School
# -------------
alias fp="cd $school/_Functional_Programming/"
# -------------
# Shortcuts
# -------------
alias ?='man'
alias i='irb'
alias m='mate'
alias d='dict'
alias e='echo'
alias f='find'
alias g='grep'
alias r='ruby'
alias c='clear'
alias a='ack -a'
alias b='botmap'
alias p='psgrep'
alias l='ls -lhp'
alias h='history'
alias t='template'
alias x='expanurl'
alias w='which -a'
alias s='easy_share'
alias o='better_open'
alias n='ruby -e "ARGV.each{|x|puts x}"'
# ----------------
# Autocomplete
# ----------------
source ~/.bash_complete
# --------
# SSHs
# --------
# See: ~/.ssh/config
# Old: ssh host.whatever.edu -l username
alias rit="ssh rit"
alias bogo="ssh bogo"
alias gibson="ssh gibson"
# --------
# Bash
# --------
alias mbashrc='mate ~/.bashrc'
alias sbashrc='source ~/.bashrc'
# -------
# Git
# -------
alias ga='git add'
alias gp='git push'
alias gb='git branch'
alias gc='git commit'
alias gs='git status'
alias glg='git lg -1'
alias gch='git checkout'
alias gba='git branch -a'
alias gsr='git svn rebase'
alias gd='git diff --binary'
alias gap="git apply $patch"
alias grm='git rebase master'
alias gca='git commit --amend'
alias gm='git checkout master'
alias glo='git log --oneline -5'
alias grc='git rebase --continue'
alias gai='git add --interactive'
alias gri='git rebase --interactive'
alias gdm='git diff --binary master'
alias gdd='git diff --binary | mate'
alias gdp='git diff --binary HEAD^ | mate'
alias gdc='git diff --binary --cached | mate'
alias gl='git log --pretty=format:"%Cgreen%h%Creset %an %s" --stat -2'
gi() { n $@ >> .gitignore; }
gh() { if [ "$1" ]; then github $*; else github browse; fi; }
gddp() { if [ "$1" ]; then f=$1; else f=$p; fi; git diff --binary > $f; }
gdpp() { if [ "$1" ]; then f=$1; else f=$p; fi; git diff --binary HEAD^ > $f; }
# -------
# SVN
# -------
rmsvn() { rm -rf `find . -type d -name .svn`; }
# --------
# Ruby
# --------
alias rspec='spec --format specdoc'
alias gemedit='gemedit --editor=mate'
alias irb='irb -r irb/completion -rubygems'
alias irb19='irb19 -r irb/completion -rubygems'
# ---------
# Rails
# ---------
alias ss='script/server'
alias sc='script/console'
alias sg='script/generate'
# --------------
# Javascript
# --------------
alias noder='rlwrap node-repl' # Node.js
alias jss='/Users/joe/code/mozilla-central/js/src/js' # Spidermonkey
alias jsso='/opt/local/bin/js' # Spidermonkey old
alias v8='rlwrap /Users/joe/code/v8/v8' # V8 Javascript Shell
alias jsr='rlwrap java -jar /Users/joe/code/env-js/rhino/js.jar' # Rhino Javascript Shell (Rhino 1.7 release 2 2009 03 22)
alias jsbom='java -jar /Users/joe/code/env-js/rhino/js.jar -f /Users/joe/code/env-js/dist/env.rhino.js -f -' # JS with BOM
alias js='/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc' # WebKit's JavaScriptCore, aka Nitro or SquirrelFish Extreme
alias narwhal='NARWHAL_ENGINE="jsc" NARWHAL_ENGINE_HOME="platforms/jsc" /Users/joe/code/narwhal/bin/narwhal'
alias narwhalr='/Users/joe/code/narwhal/bin/narwhal'
# ---------
# Prompt
# ---------
# The terminal display - "user[path](gitbranch)$ "
# - gitbranch only shows up in a git repo
# - gitbranch will have a * if there is a pending change (TURNED OFF)
# - gitbranch Source => http://gist.github.com/31631
# parse_git_dirty(){ [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"; }
# parse_git_branch(){ git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"; }
# export PS1="\u[\w]\$(parse_git_branch)$ "
parse_git_branch(){ git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1)/"; }
export PS1="\u[\w]\$(parse_git_branch)$ "
# ----------
# WebKit
# ----------
INSPECTOR_COMBINE="NO"
alias bw='build-webkit'
alias pc='prepare-ChangeLog'
alias rc='resolve-ChangeLogs'
alias br='build-inspector;run-safari'
alias bt='build-inspector;run-webkit-tests inspector'
build-images() { cp $frontend/Images/* $webkit/WebKitBuild/Release/WebCore.framework/Resources/inspector/Images; }
build-inspector() {
inspectorbuilddir="$webkit/WebKitBuild/Release/WebCore.framework/Resources/inspector"
if [ $INSPECTOR_COMBINE == "YES" ]; then
$webcore/combine-javascript-resources \
--input-html $inspector/front-end/inspector.html \
--output-dir $inspectorbuilddir \
--output-script-name inspector.js
else
cp $inspector/front-end/*.{html,js} $inspectorbuilddir
fi
cp $inspector/front-end/*.css $inspectorbuilddir
cp $webcore/English.lproj/localizedStrings.js \
$webkit/WebKitBuild/Release/WebCore.framework/Resources/English.lproj/localizedStrings.js
}
trac() {
path=`echo $(path $1) | ruby -pe 'sub(/^.*WebKit\//,"")'`
url="http://trac.webkit.org/browser/trunk/$path"
if [ "$2" ]; then
o "$url#L$2"
else
o $url
fi
}
# -------------
# Functions
# -------------
# Open a script on the path in textmate
wm() {
`which $1 | xargs mate`
}
# Rerun the last cmd and put its output into the clipboard
copy() {
eval `history | line -s -2 | sed -r "s/[0-9]+//"` | pb;
}
# Just take the last command and put that command into the clipboard
copycmd() {
echo `history | line -s -2 | sed -E "s/[0-9]+[ \t]+//"` | pb;
}
# Better Copy to Clipboard
pb() {
ruby -e "print STDIN.readlines.to_s.strip()" | pbcopy;
}
# Get the fileurl of the current directory or the given file
fileurl() {
if [ "$1" ]
then echo "file://$(pwd)/$1"
else echo "file://$(pwd)"
fi
}
# Get the full path of the current directory or the given file
path() {
if [ "$1" ]
then echo "$PWD/$1"
else pwd
fi
}
# Shortcut for `open` but no arguments opens the current directory
better_open() {
if [ "$1" ]
then `open "$1"`
else `open .`
fi
}
# Append to an Environmental Variable
addto() {
old=`env | grep "^$1=" | sed "s/^$1=//"`
export $1=$old:$2
}
# Output a dictionary lookup immediately
# Source: http://github.com/isaacs/dotfiles/blob/master/.extra.bashrc
dict () {
curl -s dict://dict.org/d:$1 | perl -ne 's/\r//; last if /^\.$/; print if /^151/../^250/'
}
# Lookup in the Apple Dictionary
# Source: http://hayne.net/MacDev/Bash/aliases.bash
odict() {
open dict:///"$@";
}
# Convenience for printing awk fields
# NOTE: when making a public script use `cut`
fawk() {
CMD="{print \$$1"
shift
while [ $# -gt 0 ]; do
CMD=$CMD",\$$1"
shift
done
CMD=$CMD'}'
awk "$CMD"
}
# Handy Extract Program
# Source: http://www.shell-fu.org/lister.php?id=375
# Modifications: added jar, removed 7z and rar
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.gz) gunzip $1 ;;
*.jar) jar xf $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Cool History Summerizer
historyawk(){ history|awk '{a[$2]++}END{for(i in a){printf"%5d\t%s\n",a[i],i}}'|sort -nr|head; }
# cd directly to a dir and list contents
cdl() {
if [ "$1" ]
then builtin cd "$1" && ll
else builtin cd && ll
fi
}
# mkdir and cd directly to it
mkdirc() {
if [ "$1" ]
then mkdir -p "$1" && cd "$1"
fi
}
# Open a new terminal tab in the same directory as the current
# SOURCE => http://pastie.caboo.se/188640
# AND => http://justinfrench.com/index.php?id=231
nth() {
osascript -e "
Tell application \"Terminal\"
activate
tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down
do script with command \"cd '$(pwd)'; clear\" in selected tab of the front window
end tell"
}
# Merge two directories. Copying over files.
# Usage: merge dir1 dir2
# This copies everything in dir1 INTO dir2, overwriting same named files
dirmerge() {
if [[ $# == 2 ]]; then
dir1=$1
dir2=$2
echo "Merging $1 into $2"
cp -R -v $1/* $2
else
echo 'usage: dirmerge dir1 dir2'
fi
}
# Convert a Man Page to a PDF, really slick
# SOURCE => http://dotfiles.org/~miragj/.bashrc
pman() { man -t "$1" | open -f -a /Applications/Preview.app/; }
# Run .profile (MacPorts)
source ~/.profile
# Count lines of code in a [1:dir] or the current
# working directory.
# SOURCE: http://github.com/visionmedia/dotfiles/blob/master/.bash_profile
function lc {
dir=${1:-.}
awk=''
# Extensions
exts=( c h rb rake module inc php install js css haml sass erb )
exts_pattern=`echo ${exts[*]} | tr " " "|"`
# AWK iteration
for (( i = 0; i < ${#exts[*]}; i++ )); do
awk=${awk}' /\.('${exts[$i]}')$/ { '${exts[$i]}'_total += $1 }'
done
# AWK print each total
awk=${awk}' END {'
for (( i = 0; i < ${#exts[*]}; i++ )); do
awk=${awk}' printf "'${exts[$i]}' %d \\n", '${exts[$i]}'_total;'
done
# AWK print aggregated total
awk=${awk}' total = '
for (( i = 0; i < ${#exts[*]}; i++ )); do
awk=${awk}${exts[$i]}'_total + '
done
# AWK close
awk=${awk}'0; printf "total %d \\n", total; }'
echo -ne $(find "$dir" -type f | egrep '\.('"$exts_pattern"')$' | xargs wc -l | awk "$awk")
}
# PDF Merge Command, to be created later
# /usr/local/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=talking_points.pdf dbsi-notes-1.pdf dbsi-notes-2.pdf dbsi-notes-3.pdf dbsi-notes-4.pdf
# Reminder how to do neat diffs
# diff <(echo a) <(echo b)