forked from hashrocket/dotmatrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.hashrc
243 lines (219 loc) · 6.15 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
# ~/.hashrc
# vim:set ft=sh sw=2 sts=2:
[ -e "$HASHROCKET_DIR" ] || HASHROCKET_DIR="$HOME/hashrocket"
export HASHROCKET_DIR
for dir in /usr/local/bin "$HOME/bin" .git/safe/../../bin .git/bin; do
case "$PATH:" in
*:"$dir":*) PATH="`echo "$PATH"|sed -e "s#:$dir##"`" ;;
esac
case "$dir" in
/*) [ ! -d "$dir" ] || PATH="$dir:$PATH" ;;
*) PATH="$dir:$PATH" ;;
esac
done
for dir in /usr/local/sbin /opt/local/sbin /usr/X11/bin; do
case ":$PATH:" in
*:"$dir":*) ;;
*) [ ! -d "$dir" ] || PATH="$PATH:$dir" ;;
esac
done
hcd() {
cd "$HASHROCKET_DIR/$1"
if [ -e .git/safe -a ! -L .git/bin ]; then
ln -s ../bin .git
fi
}
git() {
[ -f "$HOME/.hitch_export_authors" ] && . "$HOME/.hitch_export_authors"
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"
ln -sf ../bin .git
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
echo 'if command -v hookup >/dev/null; then' >> .git/hooks/post-checkout
echo ' hookup post-checkout "$@"' >> .git/hooks/post-checkout
echo "fi" >> .git/hooks/post-checkout
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 mux
elif [ -n "$ZSH_VERSION" ]; then
compctl -/ -S '' -W "$HASHROCKET_DIR" hcd hclone mux
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
)
}
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 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+='-'
printf "${1-"(%s) "}" "${b##refs/heads/}$r$d"
fi
}
gco () {
if [[ $1 == '.' ]]; then
git add -A
git commit -m "CHECKING OUT CURRENT DIRECTORY" -q
git reset HEAD^ -q
git checkout .
else
git checkout "$@"
fi
}
alias gap='git add -p'
alias gb='git branch'
alias gc='git commit -v'
alias gca='git commit -a -v'
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 gln="git ln | perl -ple 's/\*/sprintf(\"%2s\", \$n++)/e' | less"
alias gp='git push'
alias gpr='git pull --rebase'
alias gst='git status'
alias gr='git rebase'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
alias reset-authors='git commit --amend --reset-author -C HEAD'
alias vi='vim'
bettervim="/Applications/MacVim.app/Contents/MacOS/Vim"
[ -f "$bettervim" ] && alias vim="$bettervim"
[ -f "$HOME$bettervim" ] && alias vim="$HOME$bettervim"