forked from mathiasbynens/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.functions
More file actions
206 lines (160 loc) · 4.66 KB
/
.functions
File metadata and controls
206 lines (160 loc) · 4.66 KB
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
PROJECT_ROOT="$HOME/projects"
## NPM / repo scaffolds
function npmify() {
local result=ngenplus $1 $2
if [ $result == 22 ]
then
echo "ngenplus failed!"
return
fi
nstart
}
function nstart() {
local testling=0
local travis=0
# dumb args parsing since I couldn't get getopts to work inside a function
# -a turns on travis, -s turns on testling
for v in $@
do
[[ $v == '-a' ]] && travis=1
[[ $v == '-s' ]] && testling=1
done
git init
git add .
git commit -m "initial"
hub create $(basename $PWD)
git push origin master
if [[ $travis == 1 ]]; then
travisify
travisify test
fi
if [[ $testling == 1 ]]; then
testlingify
testlingify test
fi
npm publish
}
function colingo-nstart() {
git init
git add .
git commit -m "initial"
hub create Colingo/$(basename $PWD)
git push origin master
travisify
travisify test
testlingify
testlingify test
npm publish
}
function ngenplus() {
local projectName=$1
local isFree=""
isFree="$(npm info $projectName 2>&1 | grep 'npm ERR! 404 You should bug the author to publish it')"
# if $isFree is empty then BAD. If it's not empty then GOOD
if [[ ! -n "$isFree" ]]; then
echo "$projectName already taken on npm"
npm info ${projectName} name description author
return 22
fi
local fileLocation="$(pwd)/$2"
cd $PROJECT_ROOT
ngen $1
cd $1
if [ ! -z $2 ]; then
cp "$fileLocation" ./index.js
fi
npm i
}
function colingo-ngenplus() {
local projectName=$1
local isFree=""
isFree="$(npm info $projectName 2>&1 | grep 'npm ERR! 404 You should bug the author to publish it')"
# if $isFree is empty then BAD. If it's not empty then GOOD
if [[ ! -n "$isFree" ]]; then
echo "$projectName already taken on npm"
npm info ${projectName} name description author
exit 1
fi
local fileLocation="$(pwd)/$2"
cd $PROJECT_ROOT
colingo-ngen $1
cd $1
if [ ! -z $2 ]; then
cp "$fileLocation" ./index.js
fi
npm i
}
## Git and github work flows
function pr_github() {
local branch=${1:-master}
local status="$(git status | grep 'Changes to be committed')"
if [[ -n "$status" ]]; then
echo git commit
git commit 3>&1 1>&2 2>&3
fi
local origin="$(git remote -v | grep 'origin\s' | head -n 1 | awk '{ match($0, /git@github.com\:([_a-zA-Z]+)/); split(substr($0, RSTART, RLENGTH), a, /[":]/); print a[2] }')"
local github="$(git remote -v | grep 'github\s' | head -n 1 | awk '{ match($0, /git@github.com\:([_a-zA-Z]+)/); split(substr($0, RSTART, RLENGTH), a, /[":]/); print a[2] }')"
local remote=${2:-$github}
result="$(git pull github $branch | grep 'Merge conflict in')"
if [ "$result" != "" ]; then
echo "MERGE CONFLICT ;___;"
return 1
fi
git push origin $branch
echo git push $origin $branch
exec 5>&1
echo hub pull-request -h $origin:$branch -b $remote:$branch
local uri="$( (hub pull-request -h $origin:$branch -b $remote:$branch) | tee /dev/fd/5)"
# echo "uri $uri"
# if [ "$uri" != "Aborting due to empty pull request title" && "$uri" != "" ]
# then
# echo "open $uri"
# google-chrome "$uri"
# fi
# TODO: auto merge
}
## Test & testing work flows
# file defaults to `./test`
# usage: testem-node {{file}}
function testem-node() {
# local defaultEntry="./test"
local nodeCommand
if [ ! -z $1 ]; then
nodeCommand="node $1"
else
nodeCommand="npm test"
fi
local tmpf=$(tempfile)
mv $tmpf "$tmpf.json"
local result="$tmpf.json"
# echo $result
echo '{' >> $result
echo ' "launchers": {' >> $result
echo ' "node": {' >> $result
echo " \"command\": \"$nodeCommand\"," >> $result
echo ' "protocol": "tap"' >> $result
echo ' }' >> $result
echo ' },' >> $result
echo ' "src_files": [' >> $result
echo ' "./**/*.js"' >> $result
echo ' ],' >> $result
echo ' "launch_in_dev": ["node"]' >> $result
echo '}' >> $result
# echo "$(cat $result)"
# echo testem --file="$result"
testem --file="$result"
rm $result
}
function testem-browser() {
local test_page="$HOME/testem/test-page.html"
testem --file="$HOME/testem/browser.json" \
--test_page="$test_page"
}
function testem-both() {
testem --file="$HOME/testem/both.json"
}
## Utils
function set_terminal_title() {
export ___TERMINAL_TITLE=$1
PROMPT_COMMAND='echo -ne "\033]0;${___TERMINAL_TITLE}\007"'
}