forked from sandstorm/oh-my-zsh-flow-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.plugin.zsh
350 lines (289 loc) · 8.32 KB
/
flow.plugin.zsh
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
######################################
# Section: TYPO3 Flow Autocompletion Helper
######################################
#
# the ZSH autocompletion function for TYPO3 Flow (main entry point)
#
_flow() {
if _flow_is_inside_base_distribution; then
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
if (( $CURRENT > 2 )); then
CURRENT=$CURRENT-1
local cmd=${words[2]}
shift words
_flow_subcommand
else
_flow_main_commands
fi
cd $startDirectory
fi
}
compdef _flow flow
#
# Autocompletion function for the main commands. Is executed
# from the root of the FLOW distribution.
#
_flow_main_commands() {
if [ ! -f Data/Temporary/Development/.flow-autocompletion-maincommands ]; then
mkdir -p Data/Temporary/Development/
./flow help | grep "^[* ][ ]" | php $ZSH/custom/plugins/flow/helper-postprocess-cmdlist.php > Data/Temporary/Development/.flow-autocompletion-maincommands
fi
# fills up cmdlist variable
eval "`cat Data/Temporary/Development/.flow-autocompletion-maincommands`"
_describe 'flow command' cmdlist
}
#
# Autocompletion function for a single commands. Is executed
# from the root of the TYPO3 Flow distribution.
#
_flow_subcommand() {
if [ ! -f Data/Temporary/Development/.flow-autocompletion-command-$cmd ]; then
./flow help $cmd > Data/Temporary/Development/.flow-autocompletion-command-$cmd
fi
compadd -x "`cat Data/Temporary/Development/.flow-autocompletion-command-$cmd`"
}
######################################
# Section: Internal Utility Functions
######################################
#
# Returns 0 if INSIDE a FLOW distribution, and 1 otherwise.
# can be used like:
# if _flow_is_inside_base_distribution; then ... ;fi
#
_flow_is_inside_base_distribution() {
local startDirectory=`pwd`
while [[ ! -f flow ]]; do
if [[ `pwd` == "/" ]]; then
cd $startDirectory
return 1
fi
cd ..
done
cd $startDirectory
return 0
}
######################################
# Section: FLOW Command from subdir
######################################
#
# Implementation of a FLOW command which can be executed inside
# sub directories of the FLOW distribution; just finds the base
# distribution directory and calls the appropriate FLOW command
#
flow() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
./flow $@
cd $startDirectory
}
######################################
# Section: Unit / Functional Test
######################################
#
# Implementation of a command to run unit tests
#
funittest() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
local phpunit="phpunit"
if [ -f bin/phpunit ]
local phpunit="$flowBaseDir/bin/phpunit"
cd $startDirectory
$phpunit -c $flowBaseDir/Build/BuildEssentials/PhpUnit/UnitTests.xml --colors $@
}
#
# Implementation of a command to run functional tests
#
ffunctionaltest() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
local phpunit="phpunit"
if [ -f bin/phpunit ]
local phpunit="$flowBaseDir/bin/phpunit"
cd $startDirectory
$phpunit -c $flowBaseDir/Build/BuildEssentials/PhpUnit/FunctionalTests.xml --colors $@
}
######################################
# Section: Behat (Behavioral) Tests
######################################
fbehattest() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
if [ ! -f bin/behat ]; then
echo "Behat not found, downloading flowpack/behat"
composer require --dev --prefer-source --no-interaction flowpack/behat dev-master
rm -Rf Data/Temporary
rm -Rf Build/Behat
echo "Setting up Behat..."
./flow behat:setup
fi
cd $startDirectory
$flowBaseDir/bin/behat -c $@
}
######################################
# Section: f-package-foreach
######################################
f-package-foreach() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
command=$*
baseDirectory=`pwd`
for directory in `composer status -vvv | grep "Executing command" | cut -d'(' -f2 | cut -d')' -f1 | grep -v "Packages/Libraries" | grep Packages`
do
cd "$directory"
echo ''
echo '--------------------------------------------'
echo $directory
echo '--------------------------------------------'
eval $command
cd "$baseDirectory"
done
cd $startDirectory
}
##################################################################################################
##################################################################################################
######################################
# Section: Unit / Functional Test
######################################
#
# Implementation of a command to run unit tests
#
f3unittest() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: FLOW not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
cd $startDirectory
phpunit -c $flowBaseDir/Build/Common/PhpUnit/UnitTests.xml --colors $@
}
#
# Implementation of a command to run functional tests
#
f3functionaltest() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: FLOW not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
cd $startDirectory
phpunit -c $flowBaseDir/Build/Common/PhpUnit/FunctionalTests.xml --colors $@
}
######################################
# Section: FLOW Distribution maintenance helpers
######################################
#
# Utility to choose the current FLOW distribution. Sets cdpath correctly,
# such that packages inside a distribution are found automatically.
#
f-set-distribution() {
echo "Enter the TYPO3 Flow distribution path number which should be active currently!"
echo "--------------------------------------------------------------------------"
local i=1
for thePath in $flow_distribution_paths; do
echo -n $i
echo -n " "
echo $thePath
i=` expr $i + 1`
done
echo -n "Your Choice: "
read choice
echo $flow_distribution_paths[$choice] > $ZSH/custom/plugins/flow/f-environment-choice.txt
# Now, after updating f-environment-choice.txt, send USR2 signal to
# all running ZSH instances such that they reload
ps xwwo pid,command | grep -v login | while read pid command; do
if echo $command | egrep -- "(bin/|-)zsh" >/dev/null; then
kill -USR2 $pid
fi
done
}
#
# Callback being executed when USR2 signal is fired
#
TRAPUSR2() {
_f-update-distribution-path
}
#
# Internal helper to update cdpath
#
_f-update-distribution-path() {
if [ -f $ZSH/custom/plugins/flow/f-environment-choice.txt ]; then
else
return
fi
local fBasePath=`cat $ZSH/custom/plugins/flow/f-environment-choice.txt`
# we need to add "." to the current CDPath, else Composer etc breaks...
cdpath=(. $fBasePath/Packages/Framework/ $fBasePath/Packages/Application/ $fBasePath/Packages/Sites/)
export CDPATH
}
# This helper needs to be run initially to set the CDPath correctly
_f-update-distribution-path
######################################
# Section: Open FLOW Log in iTerm 2
######################################
flogs() {
if _flow_is_inside_base_distribution; then
else
echo "ERROR: TYPO3 Flow not found inside a parent of current directory"
return 1
fi
local startDirectory=`pwd`
while [ ! -f flow ]; do
cd ..
done
local flowBaseDir=`pwd`
cd $startDirectory
flow_path="$flowBaseDir" osascript $ZSH/custom/plugins/flow/flowlog.applescript
}