forked from isaacs/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.extra.bashrc
executable file
·750 lines (665 loc) · 18.7 KB
/
.extra.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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
#!/bin/bash
######
# .extra.bashrc - Isaac's Bash Extras
# This file is designed to be a drop-in for any machine that I log into.
# Currently, that means it has to work under Darwin, Ubuntu, and yRHEL
#
# Per-platform includes at the bottom, but most functionality is included
# in this file, and forked based on resource availability.
#
# Functions are preferred over shell scripts, because then there's just
# a few files to rsync over to a new host for me to use it comfortably.
#
# .extra_Darwin.bashrc has significantly more stuff, since my mac is also
# a GUI environment, and my primary platform.
######
main () {
# Note for Leopard Users #
# If you use this, it will probably make your $PATH variable pretty long,
# which will cause terrible performance in a stock Leopard install.
# To fix this, comment out the following lines in your /etc/profile file:
# if [ -x /usr/libexec/path_helper ]; then
# eval `/usr/libexec/path_helper -s`
# fi
# Thanks to "allan" in irc://irc.freenode.net/#textmate for knowing this!
if [ "${BASH_EXTRAS_LOADED}" = "" ] && [ "$TERM_PROGRAM" != "DTerm" ] && [ "$PS1" != "" ]; then
echo "loading bash extras..."
fi
# node building
export V=
export SIGN="Developer ID Application: Joyent, Inc (X4ETB2T5LK)"
# I actually frequently forget this.
age () {
node -p <<JS
(Date.now() - (new Date('1979-07-01T19:10:00.000Z')))/(1000 * 60 * 60 * 24 * 365.25)
JS
}
# Why this is not exported in OS X, I have no idea
export HOSTNAME
alias z='date -u "+%Y-%m-%dT%H:%M:%SZ"'
alias irc='dtach -a irssi-session'
# try to avoid polluting the global namespace with lots of garbage.
# the *right* way to do this is to have everything inside functions,
# and use the "local" keyword. But that would take some work to
# reorganize all my old messes. So this is what I've got for now.
__garbage_list=""
__garbage () {
local i
if [ $# -eq 0 ]; then
for i in ${__garbage_list}; do
unset $i
done
unset __garbage_list
else
for i in "$@"; do
__garbage_list="${__garbage_list} $i"
done
fi
}
__garbage __garbage
__garbage __set_path
__set_path () {
local var="$1"
local orig=$(eval 'echo $'$var)
orig=" ${orig//:/ } "
local p="$2"
local path_elements=" ${p//:/ } "
p=""
local i
for i in $path_elements; do
if [ -d $i ]; then
p="$p $i "
# strip out from the original set.
orig=${orig/ $i / }
fi
done
for i in $orig; do
if ! [ -d $i ]; then
orig=${orig/ $i / }
fi
done
# put the original at the front, but only the ones that aren't already present
# This preserves the intended ordering, and allows env hijacking tricks like
# nave and other subshell programs use.
# p="$orig $p"
export $var=$(p=$(echo $p); echo ${p// /:})
}
__garbage __form_paths
local path_roots=( $HOME/ $HOME/local/ /usr/local/ /opt/local/ /usr/ /opt/ / )
__form_paths () {
local r p paths
paths=""
for r in "${path_roots[@]}"; do
for p in "$@"; do
paths="$paths:$r$p"
done
done
echo ${paths/:/} # remove the first :
}
# mac tar fixing
export COPYFILE_DISABLE=true
# homebrew="$HOME/.homebrew"
local homebrew="/usr/local"
__garbage homebrew
__set_path PATH "$HOME/bin:$HOME/local/nodejs/bin:/opt/nodejs/bin:/opt/local/gcc34/bin:$homebrew/share/npm/bin:$(__form_paths bin sbin libexec include):/usr/nodejs/bin/:/usr/local/nginx/sbin:$HOME/dev/js/narwhal/bin:/usr/X11R6/bin:/opt/local/share/mysql5/mysql:/usr/local/mysql/bin:/opt/local/apache2/include:/usr/X11R6/include:$homebrew/Cellar/autoconf213/2.13/bin:/Users/isaacs/.gem/ruby/1.8/bin:/opt/couchdb-1.0.0/bin:$HOME/dev/riak/rel/riak/bin:/usr/pkg/sbin:/usr/pkg/bin"
if [ -d "$HOME/Library/Application Support/TextMate/Support/bin" ]; then
export PATH=$PATH:"$HOME/Library/Application Support/TextMate/Support/bin"
fi
#__set_path LD_LIBRARY_PATH "$(__form_paths lib)"
unset LD_LIBRARY_PATH
__set_path PKG_CONFIG_PATH "$(__form_paths lib/pkgconfig):/usr/X11/lib/pkgconfig:/opt/gnome-2.14/lib/pkgconfig"
__set_path CLASSPATH "./:$HOME/dev/js/rhino/build/classes:$HOME/dev/yui/yuicompressor/src"
__set_path CDPATH ".:..:$HOME/dev:$HOME/dev/js:$HOME/dev/joyent:$HOME"
__set_path PYTHONPATH "$HOME/dev/js/node/deps/v8/tools/:$HOME/dev/js/node/tools"
# fail if the file is not an executable in the path.
inpath () {
! [ $# -eq 1 ] && echo "usage: inpath <file>" && return 1
f="$(which "$1" 2>/dev/null)"
[ -f "$f" ] && return 0
return 1
}
echo_error () {
echo "$@" 1>&2
return 0
}
alias nodee=node
js () {
local n=node
if [ -x ./node ] && [ -f ./node ]; then
echo "using ./node "$(./node --version)
n=./$n
fi
NODE_READLINE_SEARCH=1 $n "$@"
}
# Use UTF-8, and throw errors in PHP and Perl if it's not available.
# Note: this is VERY obnoxious if UTF8 is not available!
# That's the point!
# export LC_CTYPE=en_US.UTF-8
# export LC_ALL=""
# export LANG=$LC_CTYPE
# export LANGUAGE=$LANG
# export TZ=America/Los_Angeles
export HISTSIZE=10000
export HISTFILESIZE=1000000000
# I prefer to use : instead of ^ for history replacements
# much faster to type. It'd be neat to use /, but then it gets
# confused with absolute paths, like "/bin/env"
export histchars="!:#"
if ! [ -z "$BASH" ]; then
__garbage __shopt
__shopt () {
local i
for i in "$@"; do
shopt -s $i 2>/dev/null
done
}
# see http://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html#The-Shopt-Builtin
__shopt \
histappend histverify histreedit \
cdspell expand_aliases cmdhist \
hostcomplete no_empty_cmd_completion nocaseglob \
checkhash extglob globstar extdebug dirspell
fi
# A little hack to add forward-and-back traversal with cd
if inpath php && inpath godir.php; then
c () {
local a
alias cd="cd"
a="$(godir.php "$@")"
[ "$a" != "" ] && eval $a
[ -f .DS_Store ] && rm .DS_Store
alias cd="c"
}
alias cd="c"
alias ..="c .."
alias -- -="c -1"
alias -- _="c +1"
alias s="c --show"
else
alias ..="cd .."
alias -- -="cd -"
fi
# chooses the first argument that matches a file in the path.
choose_first () {
for i in "$@"; do
if ! [ -f "$i" ] && inpath "$i"; then
i="$(which "$i")"
fi
if [ -x "$i" ]; then
echo $i
break
fi
done
}
# headless <command> [<key>]
# to reconnect, do: headless "" <key>
if inpath dtach; then
headless () {
if [ "$2" == "" ]; then
hash=$(md5 -qs "$1")
else
hash="$2"
fi
if [ "$1" != "" ]; then
dtach -n /tmp/headless-$hash bash -l -c "$1"
else
dtach -A /tmp/headless-$hash bash -l
fi
}
fi
export SVN_RSH=ssh
export RSYNC_RSH=ssh
export INPUTRC=$HOME/.inputrc
export JOBS=1
# list of editors, by preference.
__edit_cmd="vim"
alias edit="${__edit_cmd}"
alias e="${__edit_cmd} ."
ew () {
edit $(which $1)
}
alias sued="sudo -e"
export EDITOR=vim
export VISUAL="$EDITOR"
__garbage __get_edit_cmd __edit_cmd
# shebang <file> <program> [<args>]
shebang () {
local sb="shebang"
if [ $# -lt 2 ]; then
echo "usage: $sb <file> <program> [<arg string>]"
return 1
elif ! [ -f "$1" ]; then
echo "$sb: $1 is not a file."
return 1
fi
if ! [ -w "$1" ]; then
echo "$sb: $1 is not writable."
return 1
fi
local prog="$2"
! [ -f "$prog" ] && prog="$(which "$prog" 2>/dev/null)"
if ! [ -x "$prog" ]; then
echo "$sb: $2 is not executable, or not in path."
return 1
fi
chmod ogu+x "$1"
prog="#!$prog"
[ "$3" != "" ] && prog="$prog $3"
if ! [ "$(head -n 1 "$1")" == "$prog" ]; then
local tmp=$(mktemp shebang.XXXX)
( echo $prog; cat $1 ) > $tmp && cat $tmp > $1 && rm $tmp && return 0 || \
echo "Something fishy happened!" && return 1
fi
return 0
}
# a friendlier delete on the command line
alias emptytrash="find $HOME/.Trash -not -path $HOME/.Trash -exec rm -rf {} \; 2>/dev/null"
lscolor=""
__garbage lscolor
if [ "$TERM" != "dumb" ] && [ -f "$(which dircolors 2>/dev/null)" ]; then
eval "$(dircolors -b)"
lscolor=" --color=auto"
fi
ls_cmd="ls$lscolor"
__garbage ls_cmd
alias ls="$ls_cmd"
alias la="$ls_cmd -Fla"
alias lah="$ls_cmd -Flah"
alias lal="$ls_cmd -FLlash"
alias ll="$ls_cmd -Flsh"
alias ag="alias | grep"
alias lg="$ls_cmd -Flash | grep --color"
export MANPAGER=more
# domain sniffing
wi () {
whois $1 | egrep -i '(registrar:|no match|record expires on|holder:)'
}
#make tree a little cooler looking.
alias tree="tree -CFa -I 'rhel.*.*.package|.git' --dirsfirst"
prof () {
unset BASH_EXTRAS_LOADED
. $HOME/.extra.bashrc
}
editprof () {
s=""
if [ "$1" != "" ]; then
s="_$1"
fi
$EDITOR $HOME/.extra$s.bashrc
prof
}
pushprof () {
[ "$1" == "" ] && echo "no hostname provided" && return 1
local failures=0
local rsync="rsync --copy-links -v -a -z"
for each in "$@"; do
if [ "$each" != "" ]; then
if $rsync $HOME/.{inputrc,profile,extra,git}* $each:~ && \
$rsync --exclude='{.git,src}/' $HOME/.{vim,gvim}* $each:~
then
echo "Pushed bash extras and public keys to $each"
else
echo "Failed to push to $each"
let 'failures += 1'
fi
fi
done
return $failures
}
if inpath brew; then
alias inst="brew install"
alias yl="brew list"
yg () {
brew list | grep "$@"
}
elif inpath apt-get; then
alias inst="sudo apt-get install"
alias yl="dpkg --list | egrep '^ii'"
yg () {
dpkg --list | egrep '^ii' | grep "$@"
}
alias upup="sudo apt-get update && sudo apt-get upgrade"
fi
# git stuff
export MANTA_KEY_ID="66:f2:21:3d:82:a8:21:f7:85:50:60:0b:5a:5e:82:f5"
export MANTA_URL=https://us-east.manta.joyent.com
export MANTA_USER=NodeCore
export GITHUB_TOKEN=$(git config --get github.token)
export GITHUB_USER=$(git config --get github.user)
export GIT_COMMITTER_NAME=${GITHUB_USER:-$(git config --get user.name)}
export GIT_COMMITTER_EMAIL=$(git config --get user.email)
export GIT_AUTHOR_NAME=${GITHUB_USER:-$(git config --get user.name)}
export GIT_AUTHOR_EMAIL=$(git config --get user.email)
grim () {
local m=${1-master}
echo "$m"
git rebase -i $m
}
alias gci="git commit"
alias gap="git add -p"
alias gst="git status"
alias glg="git lg"
alias gti="git"
alias maek="make"
alias meak="make"
alias meak="make"
alias gci-am="git commit -am"
alias authors="(echo 'Isaac Z. Schlueter <i@izs.me>'; git authors | grep -v 'isaacs' | perl -pi -e 's|\([^\)]*\)||g' | sort | uniq)"
gam () {
if [ $# -eq 0 ]; then
git ci -a
else
git ci -am "$@"
fi
}
cpg () {
rm *patch
git format-patch HEAD^
gist *patch | pbcopy
}
alias gdiff='git diff --no-index --color'
alias pbind="pbpaste | sed 's|^| |g' | pbcopy"
alias pbund="pbpaste | sed 's|^ ||g' | pbcopy"
alias pbtxt="pbpaste | pbcopy"
pbgist () {
pbpaste | gist "$@" | pbcopy
pbpaste
}
pr () {
local url="$1"
if [ "$url" == "" ] && type pbpaste &>/dev/null; then
url="$(pbpaste)"
fi
if [[ "$url" =~ ^[0-9]+$ ]]; then
local us="$2"
if [ "$us" == "" ]; then
us="origin"
fi
local num="$url"
local o="$(git config --get remote.${us}.url)"
url="${o}"
url="${url#(git:\/\/|https:\/\/)}"
url="${url#git@}"
url="${url#github.com[:\/]}"
url="${url%.git}"
url="https://github.com/${url}/pull/$num"
fi
url=${url%/commits}
url=${url%/files}
local p='^https:\/\/github.com\/[^\/]+\/[^\/]+\/pull\/[0-9]+$'
if ! [[ "$url" =~ $p ]]; then
echo "Usage:"
echo " pr <pull req url>"
echo " pr <pull req number> [<remote name>=origin]"
type pbpaste &>/dev/null &&
echo "(will read url/id from clipboard if not specified)"
return 1
fi
local root="${url/\/pull\/+([0-9])/}"
local ref="refs${url:${#root}}/head"
echo git pull $root $ref
pullup $root $ref
}
pullup () {
local me=$(git rev-list HEAD^..HEAD)
if [ $? -eq 0 ] && [ "$me" != "" ]; then
git pull "$@" && git rebase $me
fi
}
ghadd () {
local me="$(git config --get github.user)"
[ "$me" == "" ] && echo "Please enter your github name as the github.user git config." && return 1
# like: "git@github.com:$me/$repo.git"
local mine="$( git config --get remote.origin.url )"
local repo="${mine/git@github.com:$me\//}"
local nick="$1"
local who="$2"
[ "$who" == "" ] && who="$nick"
[ "$who" == "" ] && ( echo "usage: ghadd [nick] <who>" >&2 ) && return 1
# eg: git://github.com/isaacs/jack.git
local theirs="git://github.com/$who/$repo"
git remote add "$nick" "$theirs"
git fetch -a "$nick"
}
gho () {
local me="$(git config --get github.user)"
[ "$me" == "" ] && \
echo "Please enter your github name as the github.user git config." && \
return 1
# like: "git@github.com:$me/$repo.git"
local name="${1:-$(basename "$PWD")}"
local repo="git@github.com:$me/$name"
git remote add "origin" "$repo"
git fetch -a "$origin"
}
gpa () {
git push --all "$@"
}
gpt () {
git push --tags "$@"
}
gps () {
gpa "$@"
gpt "$@"
}
# Look up any ref's sha, and also copy it for pasting into bugs and such
# the echo -n bit is to remove the trailing \n
gsh () {
local c="${1:-HEAD}"
git rev-list $c^..$c | tee >(xargs echo -n | pbcopy)
}
npmswitch () {
local n1=$1
local n2=$2
curl -s http://registry.npmjs.org/-/by-user/$n1 \
| json $n1 \
| json -a \
| xargs -I P sh -x -c \
'npm cache clean P && \
npm owner add '$n2' P && \
npm owner rm '$n1' P'
}
npmgit () {
local name=$1
git clone $(npm view $name repository.url) $name
}
gf () {
git fetch -a "$1"
}
gv () {
local v=$(npm ls -pl | head -1 | awk -F: '{print $2}' | awk -F@ '{print $2}')
git ci -am $v && git tag -sm $v $v
}
nsp () {
npm explore $1 -- git pull origin master
}
alias np="npm prefix"
alias nr="npm root"
alias ngr="npm root -g"
alias ngp="npm prefix -g"
alias cdnp='cd $(npm prefix -g)'
rmnpm () {
rm -rf /usr/local/{lib/,}{node_modules,node,bin,share/man}/{.npm/,}npm* ~/.npm
}
# I can't type
gi () {
local c=${1}
cmd=("$@")
cmd[1]=${c:1}
cmd[0]=git
"${cmd[@]}"
}
# a context-sensitive rebasing git pull.
# usage:
# ghadd someuser # add the github remote account
# git checkout somebranch
# gpm someuser # similar to "git pull someuser somebranch"
# Remote branch is rebased, and local changes stashed and reapplied if possible.
gp () {
local s
local head
s=$(git stash 2>/dev/null)
head=$(basename $(git symbolic-ref HEAD 2>/dev/null) 2>/dev/null)
if [ "" == "$head" ]; then
echo_error "Not on a branch, can't pull"
return 1
fi
git fetch -a $1
git pull --rebase $1 "$head"
[ "$s" != "No local changes to save" ] && git stash pop
}
#get the ip address of a host easily.
getip () {
for each in "$@"; do
echo $each
echo "nslookup:"
nslookup $each | grep Address: | grep -v '#' | egrep -o '([0-9]+\.){3}[0-9]+'
echo "ping:"
ping -c1 -t1 $each | egrep -o '([0-9]+\.){3}[0-9]+' | head -n1
echo "dig:"
dig $each | grep . | egrep -v '^;'
done
}
# Show the IP addresses of this machine, with each interface that the address is on.
ips () {
local interface=""
local types='vmnet|en|eth|vboxnet'
local i
for i in $(
ifconfig \
| egrep -o '(^('$types')[0-9]|inet (addr:)?([0-9]+\.){3}[0-9]+)' \
| egrep -o '(^('$types')[0-9]|([0-9]+\.){3}[0-9]+)' \
| grep -v 127.0.0.1
); do
if ! [ "$( echo $i | perl -pi -e 's/([0-9]+\.){3}[0-9]+//g' )" == "" ]; then
interface="$i":
else
echo $interface $i
fi
done
}
# Like the ips function, but for mac addrs.
macs () {
local interface=""
local i
local types='vmnet|en|eth|vboxnet'
for i in $(
ifconfig \
| egrep -o '(^('$types')[0-9]:|ether ([0-9a-f]{2}:){5}[0-9a-f]{2})' \
| egrep -o '(^('$types')[0-9]:|([0-9a-f]{2}:){5}[0-9a-f]{2})'
); do
if [ ${i:(${#i}-1)} == ":" ]; then
interface=$i
else
echo $interface $i
fi
done
}
# set the bash prompt and the title function
if [ "$PROMPT_COMMAND" = "" ]; then
__prompt () {
echo -ne "\033[m";history -a
echo ""
if [ $SHLVL -gt 1 ]; then
{ local i=$SHLVL; while [ $i -gt 1 ]; do echo -n '.'; let i--; done; }
fi
local DIR=${PWD/$HOME/\~}
local HOST=${HOSTNAME:-$(uname -n)}
HOST=${HOST%.local}
echo -ne "\033]0;$(__git_ps1 "%s - " 2>/dev/null)host $HOST : dir$DIR\007"
echo -ne "$(__git_ps1 "\033[41;31m[\033[41;37m%s\033[41;31m]\033[0m" 2>/dev/null)"
echo -ne "\033[40;37m$USER@\033[42;30m$HOST\033[0m:$DIR"
if [ "$NAVE" != "" ]; then echo -ne " \033[44m\033[37m$NAVE\033[0m"
else echo -ne " \033[32m$(node -v 2>/dev/null)\033[0m"
fi
}
export PROMPT_COMMAND='__prompt'
fi
#this part gets repeated when you tab to see options
#PROMPT_COMMAND=
PS1="\n\\$ "
pres () {
# export PROMPT_COMMAND='echo;
# p=$(PWD);
# if [ ${#p} -gt 40 ]; then
# d=$(basename "$p")
# p=$(dirname "$p")
# i=$[ ${#p} - 40 ]
# p=...${p:$i}/$d
# fi
# echo -n $p
# '
export PROMPT_COMMAND=''
PS1='\n$ '
clear
}
# view processes.
alias processes="ps axMuc | egrep '^[a-zA-Z0-9]'"
pg () {
ps aux | grep "$@" | grep -v "$( echo grep "$@" )"
}
pid () {
pg "$@" | awk '{print $2}'
}
alias fh="ssh izs.me"
alias p="ssh isaacs.xen.prgmr.com"
alias dfx="ssh coal 'svcadm disable ntp;host pool.ntp.org | head -1 | awk '"'"'"'"'"'"'{print \$4}'"'"'"'"'"'"' | xargs ntpdate;svcadm enable ntp'"
# shorthand for checking on ssh agents.
sshagents () {
pg -i ssh
set | grep SSH | grep -v grep
find /tmp/ -type s | grep -i ssh
}
# shorthand for creating a new ssh agent.
agent () {
eval $( ssh-agent )
ssh-add
}
vazu () {
rsync -vazuR --stats --no-implied-dirs --delete "$@"
}
# floating-point calculations
calc () {
local expression="$@"
[ "${expression:0:6}" != "scale=" ] && expression="scale=16;$expression"
echo "$expression" | bc
}
# more handy wget for fetching files to a specific filename.
fetch_to () {
local from=$1
local to=$2
[ "$to" == "" ] && to=$( basname "$from" )
[ "$to" == "" ] && echo "usage: fetch_to <url> [<filename>]" && return 1
wget -U "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.5) Gecko/2008120121 Firefox/3.0.5" -O "$to" "$from" || return 1
}
# command-line perl prog
alias pie="perl -pi -e "
# convert dmgs to isos
dmg2iso () {
dmg="$1"
iso="${dmg%.dmg}.iso"
hdiutil convert "$dmg" -format UDTO -o "$iso" \
&& mv "$iso"{.cdr,} \
&& return 0
return 1
}
#load any per-platform .extra.bashrc files.
#__garbage arch machinearch
arch=$(uname -s)
machinearch=$(uname -m)
[ -f $HOME/.extra_$arch.bashrc ] && . $HOME/.extra_$arch.bashrc
[ -f $HOME/.extra_${arch}_${machinearch}.bashrc ] && . $HOME/.extra_${arch}_${machinearch}.bashrc
[ -f /etc/bash_completion ] && . /etc/bash_completion
[ -f /opt/local/etc/bash_completion ] && . /opt/local/etc/bash_completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
[ -f $HOME/etc/bash_completion ] && . $HOME/etc/bash_completion
inpath "git" && [ -f $HOME/.git-completion ] && . $HOME/.git-completion
inpath "npm" && . <(npm completion -s)
complete -cf sudo
# call in the cleaner.
__garbage
export BASH_EXTRAS_LOADED=1
return 0
}
main
unset main