forked from hashrocket/dotmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.hashrc
367 lines (342 loc) · 10.1 KB
/
.hashrc
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
# ~/.hashrc
# vim:set ft=sh sw=2 sts=2:
[ -e "$HASHROCKET_DIR" ] || HASHROCKET_DIR="$HOME/hashrocket"
export HASHROCKET_DIR
for dir in /opt/local/bin /usr/local/bin "$HOME/bin"; do
case "$PATH:" in
*:"$dir":*) PATH="`echo "$PATH"|sed -e "s#:$dir##"`" ;;
esac
[ ! -d "$dir" ] || PATH="$dir:$PATH"
done
for dir in /usr/local/sbin /opt/local/sbin; do
case ":$PATH:" in
*:"$dir":*) ;;
*) [ ! -d "$dir" ] || PATH="$PATH:$dir" ;;
esac
done
HASHROCKET_AUTHOR_ALOWE="Adam Lowe"
HASHROCKET_AUTHOR_BIGTIGER="Jim Remsik"
HASHROCKET_AUTHOR_BRIANDUNN="Brian Dunn"
HASHROCKET_AUTHOR_CAMEROND="Cameron Daigle"
HASHROCKET_AUTHOR_CALEBCORNMAN="Caleb Cornman"
HASHROCKET_AUTHOR_DAVELYON="Dave Lyon"
HASHROCKET_AUTHOR_DAVEOTT="Dave Ott"
HASHROCKET_AUTHOR_DESI="Desi McAdam"
HASHROCKET_AUTHOR_GREIS="Gabriel Reis"
HASHROCKET_AUTHOR_JGDAVEY="Joshua Davey"
HASHROCKET_AUTHOR_JOHMAS="John Thomas Marino"
HASHROCKET_AUTHOR_MARTINISOFT="Aaron Kalin"
HASHROCKET_AUTHOR_MATTONRAILS="Matthew Conway"
HASHROCKET_AUTHOR_NARWEN="Thais Camilo"
HASHROCKET_AUTHOR_PAULELLIOTT="Paul Elliott"
HASHROCKET_AUTHOR_RBXBX="Robert Pitts"
HASHROCKET_AUTHOR_SYNTAXRITUAL="Travis Anderson"
HASHROCKET_AUTHOR_SHANERILEY="Shane Riley"
HASHROCKET_AUTHOR_SHAYARNETT="Shay Arnett"
HASHROCKET_AUTHOR_SUPASPOIDA="Lar Van Der Jagt"
HASHROCKET_AUTHOR_THERUBYMUG="Rogelio J. Samour"
HASHROCKET_AUTHOR_TPOPE="Tim Pope"
HASHROCKET_AUTHOR_VEEZUS="Veezus Kreist"
HASHROCKET_AUTHOR_VOXDOLO="Stephen Caudill"
hcd() {
cd "$HASHROCKET_DIR/$1"
}
hpair() {
local name email args initials author ret
name=""
email="dev"
if [ -n "$ZSH_VERSION" ]; then
eval 'args=(${(i)@})'
else
args="`for arg in "$@"; do echo "x$arg"|sed -e 's/^x//'|tr ' ' _; done|sort -f`"
fi
for arg in $args; do
initials=
author=
case "x$arg" in
x-h)
echo 'hpair rocketeer1 rocketeer2'
echo 'hpair rocketeer1 gueststar1="Real Name"'
echo 'hpair -u # go solo'
echo 'hpair # status'
return 1
;;
x-e) ret=email; continue ;;
x-n) ret=name; continue ;;
x-f) ret=file; continue ;;
x-c) ret=commit; continue ;;
x-s) ret=setenv; continue ;;
x-u) ret=unsetenv; continue ;;
x-w) echo "-w is now the default" >&2; continue ;;
x-*) echo "Unknown option $arg" >&2; return 1 ;;
x*=*)
initials="`echo "$arg"|sed -e s/=.*//`"
author="`echo "$arg"|sed -e s/[^=]*=//|tr _ ' '`"
;;
[^-]*)
initials="`echo "$arg"|tr a-z A-Z`"
eval "author=\"\$HASHROCKET_AUTHOR_$initials\""
;;
esac
if [ -z "$author" ]; then
echo "Invalid id $arg" >&2
return 1
fi
name="$name and $author"
email="$email+`echo "$initials"|tr A-Z a-z`"
done
name="`echo $name|sed -e 's/^ *and *//'`"
email="[email protected]"
case "$ret" in
unsetenv) unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
rm -f "$HOME/.hpairrc"
;;
email) echo "$email" ;;
name) echo "$name" ;;
file) git config user.name "$name" && git config user.email "$email" ;;
commit)
(
if [ "" = "$name" ]; then
unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
else
export GIT_AUTHOR_NAME="$name" GIT_AUTHOR_EMAIL="$email"
fi
git commit
) ;;
*)
if [ "" = "$name" ]; then
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
else
export GIT_AUTHOR_NAME="$name" GIT_AUTHOR_EMAIL="$email"
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
rm -f "$HOME/.hpairrc"
echo "export GIT_AUTHOR_NAME=\"$GIT_AUTHOR_NAME\"" > "$HOME/.hpairrc"
echo "export GIT_AUTHOR_EMAIL=\"$GIT_AUTHOR_EMAIL\"" >> "$HOME/.hpairrc"
echo hpair >> "$HOME/.hpairrc"
fi ;;
esac
}
[ -n "$GIT_AUTHOR_EMAIL" -o ! -f "$HOME/.hpairrc" -o -z "$PS1" ] || . "$HOME/.hpairrc"
git() {
[ -f "$HOME/.hitch_export_authors" ] && . "$HOME/.hitch_export_authors"
[ -f "$HOME/.hpairrc" ] && . "$HOME/.hpairrc" >/dev/null
if command -v hub >/dev/null; then
command hub "$@"
else
command git "$@"
fi
}
hclone() {
local url basename example new
if [ x-f = "x$1" ]; then
shift
rm -rf "$HASHROCKET_DIR/`basename $1 .git`"
fi
basename="`basename $1 .git`"
if [ ! -d "$HASHROCKET_DIR/$basename" ]; then
new=1
case "$1" in
*:*) url="$1" ;;
*/*) url="[email protected]:$1.git" ;;
*) url="[email protected]:hashrocket/$1.git" ;;
esac
git clone "$url" "$HASHROCKET_DIR/$basename" || return 1
for example in "$HASHROCKET_DIR/$basename"/config/*.example.yml; do
cp "$example" "${example%.example.yml}.yml"
done 2>/dev/null
if [ -f "$HASHROCKET_DIR/$basename/.rvmrc" ] && command -v __rvm_trust_rvmrc >/dev/null; then
__rvm_trust_rvmrc "$HASHROCKET_DIR/$basename/.rvmrc"
fi
fi
hcd "$basename"
if [ ! -f .git/hooks/post-rewrite ]; then
cat > .git/hooks/post-rewrite <<EOS
#!/bin/sh
GIT_DIR="\$(dirname "\$(dirname "\$0")")"
export GIT_DIR
case "\$1" in
rebase) exec "\$GIT_DIR/hooks/post-merge" 0 rebase ;;
esac
EOS
fi
if [ ! -f .git/hooks/pre-commit ]; then
echo '#!/bin/sh' > .git/hooks/pre-commit
echo 'git diff --exit-code --cached -- Gemfile Gemfile.lock >/dev/null || bundle check' >> .git/hooks/pre-commit
fi
if [ ! -f .git/hooks/ctags ]; then
echo '#!/bin/sh' > .git/hooks/ctags
echo 'rm -f .git/tags' >> .git/hooks/ctags
echo 'ctags --tag-relative -f .git/tags --exclude=.git --exclude=db --exclude=public/uploads --exclude=vendor --exclude=tmp --languages=-javascript,html,sql -R' >> .git/hooks/ctags
chmod +x .git/hooks/ctags
for basename in post-checkout post-commit post-merge; do
echo '#!/bin/sh' > .git/hooks/$basename
echo '$GIT_DIR/hooks/ctags >/dev/null 2>&1 &' >> .git/hooks/$basename
chmod +x .git/hooks/$basename
done
.git/hooks/ctags
fi
if [ ! -f .git/hooks/bundle ]; then
cat > .git/hooks/bundle <<EOS
#!/bin/sh
unset GIT_DIR
if [ -f Gemfile ] && command -v bundle >/dev/null; then
echo 'Bundling...'
bundle check >/dev/null || bundle | grep -v '^Using ' | grep -v ' is complete'
true
fi
EOS
chmod +x .git/hooks/bundle
echo 'if command -v hookup >/dev/null; then' >> .git/hooks/post-checkout
echo ' hookup post-checkout "$@"' >> .git/hooks/post-checkout
echo "elif git diff --name-only \$1 \$2 | egrep -q '^Gemfile|\\.gemspec\$'; then" >> .git/hooks/post-checkout
echo " \$GIT_DIR/hooks/bundle" >> .git/hooks/post-checkout
echo "fi" >> .git/hooks/post-checkout
[ -z "$new" ] || .git/hooks/bundle
fi
if [ -n "$new" -a -x script/setup ]; then
script/setup
fi
}
# Tab completion
if [ -n "$BASH_VERSION" ]; then
_hcd()
{
local cur projects
[ -r "$HASHROCKET_DIR" ] || return 0
eval 'COMPREPLY=()'
cur=${COMP_WORDS[COMP_CWORD]}
projects=$(\ls "$HASHROCKET_DIR")
if [ $COMP_CWORD -eq 1 ]; then
eval 'COMPREPLY=( $(compgen -o filenames -W "$projects" $cur) )'
fi
return 0
}
complete -F _hcd hcd hclone
elif [ -n "$ZSH_VERSION" ]; then
#compdef '_files -W "$HASHROCKET_DIR"' hcd hclone
compctl -/ -W "$HASHROCKET_DIR" hcd hclone
fi
rails_root() {
(
dir=${1:-$(pwd)}
i=0
while [ "/" != "$dir" -a "$i" -ne 16 ]; do
if [ -f "$dir/config/environment.rb" ]; then
echo "$dir"
return 0
fi
dir="$(dirname "$dir")"
i=$(expr $i + 1)
done
return 1
)
}
stc() {
(
local root
root="`rails_root`"
[ -n "$root" ] || root=.
if [ "$root/config/amazon_s3.yml" -nt "$root/tmp/s3cfg" ] || [ -f "$root/config/amazon_s3.yml" -a ! -f "$root/tmp/s3cfg" ]; then
ruby -ryaml -e '
c = YAML.load(File.read(ARGV.first))[ENV["RAILS_ENV"]||"development"]
File.open(ARGV.last,"w") do |f|
f.puts "access_key = #{c["access_key_id"]}"
f.puts "secret_key = #{c["secret_access_key"]}"
end if c.kind_of?(Hash)
' "$root/config/amazon_s3.yml" "$root/tmp/s3cfg"
fi
if [ -f "$root/tmp/s3cfg" ]; then
exec s3cmd -c "$root/tmp/s3cfg" "$@"
else
exec s3cmd "$@"
fi
)
}
script_rails() {
if [ -f "`rails_root`/script/rails" ]; then
"`rails_root`/script/rails" "$@"
else
local name
name="$1"
shift
"`rails_root`/script/$name" "$@"
fi
}
twiki () {
rake db:migrate && rake db:migrate:redo && rake db:test:prepare
}
alias sc='script_rails console'
alias ss='script_rails server -u'
alias sdbc='script_rails dbconsole -p'
alias testify="watchr ~/.watchr.rb"
alias vanguard="guard -c -n false"
alias vangaurd="vanguard"
alias ll='ls -l'
# git_prompt_info accepts 0 or 1 arguments (i.e., format string)
# returns text to add to bash PS1 prompt (includes branch name)
git_prompt_info () {
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
local d
local s
# Rebasing
if [ -d "$g/rebase-apply" ] ; then
if test -f "$g/rebase-apply/rebasing" ; then
r="|REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
# Interactive rebase
elif [ -f "$g/rebase-merge/interactive" ] ; then
r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
# Merging
elif [ -f "$g/MERGE_HEAD" ] ; then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ] ; then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)" ; then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)" ; then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
# Dirty Branch
local newfile='?? '
if [ -n "$ZSH_VERSION" ]; then
newfile='\?\? '
fi
d=''
s=$(git status --porcelain 2> /dev/null)
[[ $s =~ "$newfile" ]] && d+='+'
[[ $s =~ "M " ]] && d+='*'
[[ $s =~ "D " ]] && d+='-'
if [ -n "${1-}" ]; then
printf "$1" "${b##refs/heads/}$r$d"
else
printf "(%s) " "${b##refs/heads/}$r$d"
fi
fi
}
alias gap='git add -p'
alias gb='git branch'
alias gc='git commit -v'
alias gca='git commit -a -v'
alias gco="git checkout"
alias gd='git diff'
alias gdc='git diff --cached'
alias gdh='git diff HEAD'
alias gl='git pull'
alias glod='git log --oneline --decorate'
alias gp='git push'
alias gpr='git pull --rebase'
alias grep='grep --color=auto --exclude="*~"'
alias gst='git status'
alias gr='git rebase'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
alias vi='vim'