-
Notifications
You must be signed in to change notification settings - Fork 0
/
observe
executable file
·1069 lines (944 loc) · 44.8 KB
/
observe
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
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -u
#
# C H E C K H O W C O M P U T E R H A N D L E S E R R O R S --Start
#
test_positives(){
KIND=""
local -i _err=0
if ls werwerwerwerwerwerwerwerwerwerwerr >/dev/null 2>&1; then
_err=$?
if (( _err == 0 )) ; then # Intel processor
KIND="INTEL"
fi
if [ $_err == 0 ]; then # Mac Intel processor
KIND="${KIND}MAC"
fi
else
if (( _err == 0 )) ; then # Intel processor
KIND="INTEL"
fi
if [ $_err == 0 ]; then # Mac Intel processor
KIND="${KIND}MAC"
fi
fi
echo "${KIND}"
}
PROCESSOR_ERROR=$(test_positives)
# DEBUG MACPOSITIVE MACPOSITIVE echo "${PROCESSOR_ERROR}"
# DEBUG MACPOSITIVE exit 1
#
# C H E C K H O W C O M P U T E R H A N D L E S E R R O R S --End
#
#
# C H E C K R E P L A C E F U N C T I O N S I N S T A L L E D --Start
#
check_replacer () {
local REPLACER="$1"
if command -v "${REPLACER}" >/dev/null 2>&1; then
# It looks installed
# .. is it working properly
# msg_green " ${1} INSTALLED."
#stdout UND stderr -capture REF: https://www.thomas-krenn.com/de/wiki/Bash_stdout_und_stderr_umleiten
${REPLACER} --version &> /tmp/ersetze_test_${REPLACER}.txt
# shellcheck disable=SC2155
local PROPERLYWORKING=$(cat /tmp/ersetze_test_${REPLACER}.txt)
if [[ "$PROPERLYWORKING" == *"dyld:"* ]]; then { echo "error"; return;} fi
if [[ "$PROPERLYWORKING" == *"GNU"* ]]; then { echo "GNU"; return;} else { echo "MAC";return;} fi
echo "checked";
return;
else
# msg_red "${GREEN} ${RED} CANNOT REPLACE ...${1} IS MISSING ";
# msg_red " NEED TO INSTALL ${1}. Linux: sudo apt-get install ${1} Mac: brew install ${1} "
echo "install";
return;
fi
}
function msg_install() {
msg_red "${GREEN} ${RED} CANNOT REPLACE ...${1} IS MISSING ";
msg_red " NEED TO INSTALL ${1}. Linux: sudo apt-get install ${1} Mac: brew install ${1} "
}
# REPLACER="sed";
# Try vim's ex ..broke here grrr TODO research how to implement doing erestese_indatei /images/projects/ images/projects index.html did not work at all
REPLACER="sed"; # changed to sed
VALIDREPLACER=$(check_replacer "${REPLACER}")
if [[ $VALIDREPLACER == "error" ]] ; then
msg_red "Error with replacer ${REPLACER}"
msg_red " - Error:"
cat /tmp/ersetze_test_${REPLACER}.txt
rm /tmp/ersetze_test_${REPLACER}.txt
fi
if [[ $VALIDREPLACER == "install" ]] ; then
msg_install "${REPLACER}"
fi
rm /tmp/ersetze_test_${REPLACER}.txt
# TODO - Remove Repetition HERE
# ? empty still
if [[ $VALIDREPLACER == "install" || $VALIDREPLACER == "error" ]] ; then
REPLACER="sed";
VALIDREPLACER=$(check_replacer "${REPLACER}")
if [[ $VALIDREPLACER == "error" ]] ; then
msg_red "Error with replacer ${REPLACER}"
msg_red " - Error:"
cat /tmp/ersetze_test_${REPLACER}.txt
rm /tmp/ersetze_test_${REPLACER}.txt
exit 1;
fi
if [[ $VALIDREPLACER == "install" ]] ; then
msg_install "${REPLACER}"
rm /tmp/ersetze_test_${REPLACER}.txt
exit 1;
fi
fi
REPLACERGNU="NO"
if [[ $VALIDREPLACER == "GNU" ]] ; then
{
REPLACERGNU="YES"
}
fi
# one more check for gsed from brew in macs
if [[ $REPLACERGNU == "NO" ]] ; then
{
if command -v gsed >/dev/null 2>&1 ; then
{
REPLACERGNU="YES"
REPLACER="gsed"
}
fi
}
fi
# Test
# echo "REPLACERGNU: $REPLACERGNU"
# echo "VALIDREPLACER: $VALIDREPLACER"
# exit
# C H E C K R E P L A C E F U N C T I O N S I N S T A L L E D -- RESULTS
# Results as
# $REPLACERGNU NO OR YES
# $REPLACERGNU ex or sed
# halts execution if not found
#
# C H E C K R E P L A C E F U N C T I O N S I N S T A L L E D -- End
[ -z ${1-} ] && echo "Expected at least one parameter for filename to observe!." && exit 1
typeset pwd_backslash_escaped_for_sed=$(pwd | sed 's@/@\\/@g')
function file_extension() {
#
# Outputs the file extension given a file name
#
# $1 = Filename.ext:linenummer
#
# Usage: extension=$(file_extension "foo/bar.baz")
# Result: $extension ==> "baz"
#
#
local test_value=$(echo "${1##*.}")
if [[ "${test_value}" == *":"* ]] ; then
{
echo "${test_value}" | cut -d":" -f1
}
else
{
echo "${test_value}"
}
fi
} # end file_extension
function _trap_on_INT(){
local -ir __trapped_INT_num="${2:-0}"
echo -e "\\n \033[01;7m*** 7 INT TRAP $THISSCRIPTNAME \\n${BASH_SOURCE}:${BASH_LINENO[-0]} ${FUNCNAME[1]}() \\n$0:${BASH_LINENO[1]} ${FUNCNAME[2]}() \\n$0:${BASH_LINENO[2]} ${FUNCNAME[3]}() \\n INT ...\033[0m \n \n "
echo ". ${1}"
echo ". INT ${__trapped_INT_num} "
echo ". caller $(caller) "
echo ". ${BASH_COMMAND}"
local -r __caller=$(caller)
local -ir __caller_line=$(echo "${__caller}" | cut -d' ' -f1)
local -r __caller_script_name=$(echo "${__caller}" | cut -d' ' -f2)
awk 'NR>L-10 && NR<L+10 { printf "%-10d%10s%s\n",NR,(NR==L?"☠ » » » > ":""),$0 }' L="${__caller_line}" "${__caller_script_name}"
# $(eval ${BASH_COMMAND} 2>&1; )
# echo -e " ☠ ${LIGHTPINK} Offending message: ${__bash_error} ${RESET}" >&2
exit ${__trapped_INT_num}
} # end _trap_on_INT
# trap '_trap_on_INT $0 "${?}" LINENO BASH_LINENO FUNCNAME BASH_COMMAND $FUNCNAME $BASH_LINENO $LINENO $BASH_COMMAND' INT ERR
function _ignore_ruby_list(){
# Sample use
# _ignore_ruby_list "${one-}"
# _err=$?
# [ ${_err} -gt 0 ] && continue # skip ignored files
local file_to_test="${1}"
local -i _found=0
local ONE_FILENAME FILESTOEXCLUDE="
config/brakeman.ignore
"
while read -r ONE_FILENAME; do
{
[[ -z "${ONE_FILENAME}" ]] && continue # skip if empty
echo "Comparing ${ONE_FILENAME} vs ${file_to_test}"
if [[ "${ONE_FILENAME}" == "${file_to_test}" ]] ; then
{
_found=1
echo " \___ ig matched"
break
}
fi
}
done <<< "${FILESTOEXCLUDE}"
return ${_found}
} # end _ignore_ruby_list
function _is_duplicated(){
# Sample use
# _is_duplicated "${1}" "${@:2}"
# _is_duplicated "Gemfile" "
# config/brakeman.ignore
# "
# _err=$?
# [ ${_err} -gt 0 ] && continue # skip duplicated files
local file_to_test="${1}"
local -i _found=0
local ONE_FILENAME FILESTOEXCLUDE="${*:2}"
while read -r ONE_FILENAME; do
{
[[ -z "${ONE_FILENAME}" ]] && continue # skip if empty
echo "Comparing ${ONE_FILENAME} vs ${file_to_test}"
if [[ "${ONE_FILENAME}" == "${file_to_test}" ]] ; then
{
_found=1
echo " \___ dup matched"
break
}
fi
}
done <<< "${FILESTOEXCLUDE}"
return ${_found}
} # end _is_duplicated
function _main(){
# set -exu
local -i _err=0
local file_to_observe="${1-}"
local extension_to_observe=$(file_extension "${1-}")
local observe_one_line=""
if ( grep -q ":" <<< "${file_to_observe}" ) ; then
{
observe_one_line="${file_to_observe}"
local cut_file_number="$(cut -d: -f1 <<< "${file_to_observe}" )"
extension_to_observe=$(file_extension "${cut_file_number:-}")
file_to_observe="${cut_file_number}"
}
fi
local extra_args_to_run="${*:2}"
local prefix_to_run=""
local file_to_watch="\"./\""
local _filename=${file_to_observe##*/} # get only last filename
local _script_name=".${_filename}.watch.test.bash"
local _rubocops=""
local _rpec_file="watch(%r{^${_filename}\$})"
local replacer_colors_prefix=$(cat <<-EOF
#!/usr/bin/env bash
# set -exu
pathpat="(/[^/]*)+:[0-9]+"
ccred=\$(echo -e "\033[0;31m")
ccyellow=\$(echo -e "\033[0;33m")
ccend=\$(echo -e "\033[0m")
# sed -E
# -e "/[Ee]rror[: ]/ s%\$pathpat%\$ccred&\$ccend%g"
# -e "/[Ww]arning[: ]/ s%\$pathpat%\$ccyellow&\$ccend%g"
EOF
)
# echo "${replacer_colors_prefix}"
# exit 0
local replacer_colors_sufix2=""
local replacer_colors_sufix3=""
local replacer_colors_sufix=$(cat <<-EOF
| ${REPLACER} --unbuffered '/\ process\ jobs\ in\ this\ environment/d' \\
| ${REPLACER} --unbuffered '/Top\ level\ /d' \\
| ${REPLACER} --unbuffered '/DEPRECATION WARNING..desired_principal_rate_change_amount=/d' \\
| ${REPLACER} --unbuffered '/app.commands.loan.applications.create.rb.../d' \\
| ${REPLACER} --unbuffered '/block....levels/d' \\
| ${REPLACER} --unbuffered '/\ warning:\ already\ initialized\ constant/d' \\
| ${REPLACER} --unbuffered '/\ was\ here/d' \\
| ${REPLACER} --unbuffered 's/\ on\ line\ /:/g' \\
| ${REPLACER} --unbuffered 's/:\ line\ /:/g' \\
| ${REPLACER} --unbuffered 's/\ No\ such\ file\ or\ directory\ in\ /\ in\ \o033[38;5;213m/g' \\
| ${REPLACER} --unbuffered 's/\,\ no\ offenses\ /\,\ \o033[01;32m no\ offenses\ \o033[0m/g' \\
| ${REPLACER} --unbuffered 's/\ examples\,\ 0\ failures/\o033[01;32m\ examples\,\ 0\ failures \o033[0m/g' \\
| ${REPLACER} --unbuffered 's/\ returns\ /\o033[01;32m\ returns\ /g' \\
| ${REPLACER} --unbuffered 's/\ Do\ not\ use\ /\o033[48;5;235m\o033[38;5;196m\ Do\ not\ use\ /g' \\
| ${REPLACER} --unbuffered 's/..Failure.Error:/\o033[48;5;235m\o033[38;5;196m..Failure.Error:/g' \\
| ${REPLACER} --unbuffered 's/.FAILED\ /\o033[48;5;235m\o033[38;5;196m...FAILED\ \o033[0m/g' \\
| ${REPLACER} --unbuffered 's/.failures:/\o033[48;5;235m\o033[38;5;196m.failures\o033[0m:/g' \\
| ${REPLACER} --unbuffered 's/\ in\ tests\./\ in\ tests\.\o033[0m/g' \\
| ${REPLACER} --unbuffered 's/expected\ the\ /\o033[0mexpected\ the\ /g' \\
| ${REPLACER} --unbuffered 's/\[Command\ was\ successful\]/\o033[01;32m\[Command\ was\ successful\]/g' \\
| ${REPLACER} --unbuffered 's/\ GET\ /\o033[01;35m\ GET\ /g' \\
| ${REPLACER} --unbuffered 's/\ POST\ /\o033[01;35m\ POST\ /g' \\
| ${REPLACER} --unbuffered 's/\ DELETE\ /\o033[01;35m\ DELETE\ /g' \\
| ${REPLACER} --unbuffered 's/\ PUT\ /\o033[01;35m\ PUT\ /g' \\
| ${REPLACER} --unbuffered 's/\ PATCH\ /\o033[01;35m\ PATCH\ /g' \\
| ${REPLACER} --unbuffered 's/\ OPTIONS\ /\o033[01;35m\ OPTIONS\ /g' \\
| ${REPLACER} --unbuffered 's/Top\ /\o033[38;5;100mTop\ /g' \\
| ${REPLACER} --unbuffered 's/\ seconds\ /\o033[38;5;231m\ seconds\ /g' \\
| ${REPLACER} --unbuffered 's/\ behaves\ like\ /\o033[01;36m\ behaves\ like\ /g' \\
| ${REPLACER} --unbuffered 's/\ when\ /\o033[01;36m\ when\ /g' \\
| ${REPLACER} --unbuffered 's/\ do\ /\o033[0m\ do\ /g' \\
| ${REPLACER} --unbuffered 's/\ does\ /\o033[0m\ does\ /g' \\
| ${REPLACER} --unbuffered 's/\ finds\ /\o033[0m\ finds\ /g' \\
| ${REPLACER} --unbuffered 's/\ serializes\ /\o033[0m\ serializes\ /g' \\
| ${REPLACER} --unbuffered 's/ErrorException:\ /\o033[38;5;196mErrorException:\ \o033[38;5;213m/g' \\
| ${REPLACER} --unbuffered "s/\ require_once(.\/wp-content/\ require_once(\n$pwd_backslash_escaped_for_sed\/wp-content/g" \\
| ${REPLACER} --unbuffered "s/\ require(.\/wp-content/\ require(\n$pwd_backslash_escaped_for_sed\/wp-content/g" \\
| ${REPLACER} --unbuffered "s/\ require\ .\/wp-content/\ require\ \n$pwd_backslash_escaped_for_sed\/wp-content/g" \\
| ${REPLACER} --unbuffered "s/\ include\ .\/wp-content/\ include\ \n$pwd_backslash_escaped_for_sed\/wp-content/g" \\
| ${REPLACER} --unbuffered "s/\ include_once(.\/wp-content/\ include_once(\n$pwd_backslash_escaped_for_sed\/wp-content/g" \\
| ${REPLACER} --unbuffered "s/\ in\ \//\ in\ \n\//g" \\
| ${REPLACER} --unbuffered 's/Stack\ trace:/\o033[38;0mStack\ trace:/g' \\
| ${REPLACER} --unbuffered 's/Call\ Stack:/\o033[38;0mCall\ Stack:/g' \\
| ${REPLACER} --unbuffered 's/#. //g' \\
| ${REPLACER} --unbuffered -E "/[Ee]rror[: ]/ s%\$pathpat%\$ccred&\$ccend%g" \\
| ${REPLACER} --unbuffered -E "/[Ww]arning[: ]/ s%\$pathpat%\$ccyellow&\$ccend%g" \\
| ${REPLACER} --unbuffered 's/\.\/spec\//\o033[0m\.\/spec\//g' \\
EOF
)
# | ${REPLACER} --unbuffered 's/[^[:alpha:]#]\+/\o033[01;35m\ /g' \\
if [[ "${extension_to_observe-}" == "go" ]] ; then
{
# GO
# ps aux | grep "${1-}" | head -1 |xargs
prefix_to_run="[[ -n \\\"\$(ps aux | grep \\\"${1-}\\\" | grep -v 'grep' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps aux | grep \\\"${1-}\\\" | grep -v 'grep' | head -1 | xargs | cut -d' ' -f2 )\\\" || go run \\\"$(pwd)/${*}\\\" && go run "
file_to_watch="$(pwd)/"
extension_to_observe="go"
}
elif [[ "${extension_to_observe-}" == "toml" ]] && [[ "${file_to_observe-}" == "Cargo.toml" ]] ; then
{
# Rust TOML
# cargo run --package progress --bin project_name
# ps aux | grep "${1-}" | head -1 |xargs
# nodemon --watch "$(pwd)/src" --ext rs --exec "cargo run -q $(pwd)/Cargo.toml"
# ps aux | grep "Cargo.toml" | grep -v 'grep' | grep -v 'nodemon'
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || cargo run -q \\\"$(pwd)/${file_to_observe-}\\\" && cargo run -q "
file_to_watch="$(pwd)/src"
extension_to_observe="rs"
}
elif [[ "${extension_to_observe-}" == "xml" ]] && [[ "${file_to_observe-}" == "pom.xml" ]] ; then
{
# Java Spring Boot pom.xml
# check operation systems
local linuxy=0
local windowxy=0
if [[ "$(uname)" == "Darwin" ]] ; then
linuxy=1
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]] ; then
linuxy=1
elif [[ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]] || [[ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]] ; then
windowxy=1
linuxy=0
fi
local open_cmd
case "$OSTYPE" in # this var OSTYPE is a global on linuxes and macs usually
(darwin*) linuxy=1 ;;
(cygwin*) windowxy=1 ; linuxy=1 ;;
(linux*) linuxy=1 ;;
(msys*) windowxy=1 ; linuxy=1 ;;
(*) echo "Platform $OSTYPE / $(uname) / $(expr substr $(uname -s) 1 5) / $(expr substr $(uname -s) 1 10) / not supported"
return 1 ;;
esac
echo "compile using Javac like ActiveJ"
echo "javac -classpath path/to/activej/libs/*.jar YourMainClass.java"
echo "run activej"
echo "java -jar target/your-application.jar"
echo "run manually activej"
echo "java -classpath path/to/activej/libs/*.jar:. YourMainClass"
# mvn spring-boot:run
if ( command -v mvn >/dev/null 2>&1; ) ; then
echo "mvn spring-boot:run -Dspring-boot.run.profiles=prod"
echo "mvn clean package"
echo "debug dev local:"
echo "mvn spring-boot:run"
if [ -e build.gradle.kts ] ; then
# kotlink ktor
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || mvn compile exec:java -Dexec.mainClass=\\\"your.main.Class\\\" \\\"$(pwd)/${file_to_observe-}\\\" && mvn compile exec:java -Dexec.mainClass=\\\"your.main.Class\\\" "
else
# spring boot
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || mvn spring-boot:run \\\"$(pwd)/${file_to_observe-}\\\" && mvn spring-boot:run "
fi
else
echo "./gradlew bootRun --args='--spring.profiles.active=prod'"
echo "debug dev local:"
echo "./gradlew bootRun"
echo "Create Jar"
echo "./gradlew build"
echo "java -jar target/yourapp-0.0.1-SNAPSHOT.jar"
if [ ${linuxy} -eq 1 ] && [ ${windowxy} -eq 0 ] ; then
if ( command -v ./gradlew >/dev/null 2>&1; ) ; then
if [ -e build.gradle.kts ] ; then
# kotlink ktor
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || ./gradlew run \\\"$(pwd)/${file_to_observe-}\\\" && ./gradlew run "
else
# spring boot
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || ./gradlew bootRun \\\"$(pwd)/${file_to_observe-}\\\" && ./gradlew bootRun "
fi
fi
elif [ ${linuxy} -eq 1 ] && [ ${windowxy} -eq 0 ] ; then # cygwin or msys
if ( command -v gradlew.bat >/dev/null 2>&1; ) ; then
if [ -e build.gradle.kts ] ; then
# kotlink ktor
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || gradlew.bat run \\\"$(pwd)/${file_to_observe-}\\\" && gradlew.bat run "
else
# spring boot
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || gradlew.bat bootRun \\\"$(pwd)/${file_to_observe-}\\\" && gradlew.bat bootRun "
fi
fi
else
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs)\\\" ]] && kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | grep -v 'nodemon' | head -1 | xargs | cut -d' ' -f2 )\\\" || gradlew.bat bootRun \\\"$(pwd)/${file_to_observe-}\\\" && gradlew.bat bootRun "
fi
fi
file_to_watch="$(pwd)/"
extension_to_observe="java"
}
elif [[ "${extension_to_observe-}" == "java" ]] ; then
{
# java
# java project_file
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs | cut -d' ' -f2 )\\\" || java \\\"$(pwd)/${file_to_observe-}\\\" && java "
file_to_watch="$(pwd)/"
extension_to_observe="java"
extra_args_to_run=""
}
elif [[ "${extension_to_observe-}" == "bash" ]] ; then
{
# bash
# bash project_file
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs | cut -d' ' -f2 )\\\" || bash \\\"$(pwd)/${file_to_observe-}\\\" && bash "
file_to_watch="$(pwd)/"
extension_to_observe="bash"
extra_args_to_run=""
}
elif [[ "${extension_to_observe-}" == "py" ]] ; then
{
# python
# python project_file
# ps aux | grep "${1-}" | head -1 |xargs
ps axt | grep live-server | grep coverage |xargs | cut -d\ -f1 |xargs -I {} kill {}
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs | cut -d' ' -f2 )\\\" || python \\\"$(pwd)/${file_to_observe-}\\\" && python "
file_to_watch="$(pwd)/"
extension_to_observe="py"
}
elif [[ "${extension_to_observe-}" == "rb" ]] ; then
{
# ruby
extension_to_observe="rb"
if ( grep -q "_spec.rb[[:space:]]*$" <<< "${file_to_observe-}" ) || ( grep -q '_spec.rb' <<< "${file_to_observe-}" ) ; then # if ends with or contains
{
# rspec yes ?
# kill live-server coverage
ps axt | grep live-server | grep coverage |xargs | cut -d\ -f1 |xargs -I {} kill {}
# one file
local extra_args_to_run_preview=""
if [[ -n "${observe_one_line}" ]] ; then # Criteria: if one numeric : then pass only one test to run but keep observing other files
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"$(pwd)/${file_to_observe-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${observe_one_line-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
else
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"$(pwd)/${file_to_observe-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${file_to_observe-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
fi
local _files_to_rubocop="$(pwd)/${file_to_observe-}"
local _files_to_rspec="$(pwd)/${file_to_observe-}"
file_to_watch="$(pwd)/${file_to_observe-}"
# try to find related classed from described yes ?
local _maybe_control_list="${file_to_observe-}"
local _maybe_name=""
local _maybe_name2=""
# echo "${file_to_observe-}"
# cat "${file_to_observe-}" | grep "^[[:space:]]*RSpec.describe"
# grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe"
# grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe" | xargs
grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe" | xargs | cut -d' ' -f1 | cut -d, -f1
_maybe_name=$(grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe" | xargs | cut -d' ' -f1 | cut -d, -f1) # assume tests use only this format
echo " _maybe_name:${_maybe_name-}"
grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe" | xargs | cut -d' ' -f1 | cut -d, -f1 | sed 's/:/\n/g' | tail -1
_maybe_name2=$(grep "^[[:space:]]*RSpec.describe" < "${file_to_observe-}" | cuet "RSpec.describe" | xargs | cut -d' ' -f1 | cut -d, -f1 | sed 's/:/\n/g' | tail -1) # assume tests use only this format
echo " _maybe_name2:${_maybe_name2-}"
if [[ -n "${_maybe_name}" ]] ; then
{
if ( ag -l "${_maybe_name}" | grep -v '_spec.rb' ) ; then # list all found filenames with ag with out other tests
{
local _possible_related_classes=""
_rubocops="watch(%r{^${file_to_watch}\.rb\$})"
_possible_related_classes="$( ag -l "${_maybe_name}" | grep -v '_spec.rb' )"
echo "_possible_related_classes:${_possible_related_classes-}"
if [[ -n "${_possible_related_classes}" ]] ; then
{
local one=""
local _found=0
while read -r one ; do
{
[[ -z "${one-}" ]] && continue # skip empty lines
[[ -f "${one-}" ]] || continue # only if file exists
_ignore_ruby_list "${one}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip ignored files
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
file_to_watch="${file_to_watch}\"\\
--watch \"$(pwd)/${one}"
_files_to_rubocop="${_files_to_rubocop}\\\"\\
\\\"$(pwd)/${one}"
_rubocops="${_rubocops}
watch(%r{^$(pwd)/${one}\$})"
_maybe_control_list="${_maybe_control_list}
${one}"
_found=$(( _found + 1 ))
}
done <<< "${_possible_related_classes}"
# multiple files
if [ ${_found} -gt 0 ] ; then
{
if [[ -n "${observe_one_line}" ]] ; then # Criteria: if one numeric : then pass only one test to run but keep observing other files
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${observe_one_line-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
else
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"${_files_to_rspec-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
fi
}
fi
_found=0
local __all_passed_files="$( sed 's/\.rb\ /.rb\n/g' <<< "${*-}")"
echo __all_passed_files:"${__all_passed_files}"
while read -r one ; do
{
[[ -z "${one-}" ]] && continue # skip empty lines
[[ -f "${one-}" ]] || continue # only if file exists
_ignore_ruby_list "${one}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip ignored files
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
file_to_watch="${file_to_watch}\"\\
--watch \"$(pwd)/${one}"
_files_to_rubocop="${_files_to_rubocop}\\\"\\
\\\"$(pwd)/${one}"
_rubocops="${_rubocops}
watch(%r{^$(pwd)/${one}\$})"
if ( grep -q "_spec.rb[[:space:]]*$" <<< "${one}" ) ; then
{
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
_maybe_control_list="${_maybe_control_list}
${one}"
_files_to_rspec="${_files_to_rspec}\\\"\\
\\\"$(pwd)/${one}"
}
else
{
_maybe_control_list="${_maybe_control_list}
${one}"
}
fi
_found=$(( _found + 1 ))
}
done <<< "${__all_passed_files}"
# multiple files
echo _files_to_rspec:"${_files_to_rspec}"
## DEBUG exit 0
if [ ${_found} -gt 0 ] ; then
{
if [[ -n "${observe_one_line}" ]] ; then # Criteria: if one numeric : then pass only one test to run but keep observing other files
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${observe_one_line-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
else
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"${_files_to_rspec-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
fi
}
fi
replacer_colors_sufix2=$(cat <<-EOF
| ${REPLACER} --unbuffered 's/"${_maybe_name-}"/\o033[38;5;178m"${_maybe_name-}"\o033[0m/g' \\
| ${REPLACER} --unbuffered 's/"${_maybe_name-}"/\o033[38;5;178m"${_maybe_name-}"\o033[0m/g' \\
EOF
)
# | ${REPLACER} --unbuffered 's@/./@/@g' \\
} # end [[ -n "${_possible_related_classes}" ]]
fi
} # end ag -l "${_maybe_name}" | grep -v '_spec.rb'
fi
} # end [[ -n "${_maybe_name}" ]]
fi
if [[ -n "${_maybe_name2}" ]] ; then
{
if ( ag -l "${_maybe_name2}" | grep -v '_spec.rb' ) ; then # list all found filenames with ag with out other tests
{
local _possible_related_classes=""
# _rubocops="watch(%r{^${file_to_watch}\.rb\$})"
_possible_related_classes="$( ag -l "${_maybe_name2}" | grep -v '_spec.rb' )"
echo "_possible_related_classes:${_possible_related_classes-}"
if [[ -n "${_possible_related_classes}" ]] ; then
{
local one=""
local _found=0
while read -r one ; do
{
[[ -z "${one-}" ]] && continue # skip empty lines
[[ -f "${one-}" ]] || continue # only if file exists
_ignore_ruby_list "${one}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip ignored files
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
file_to_watch="${file_to_watch}\"\\
--watch \"$(pwd)/${one}"
_files_to_rubocop="${_files_to_rubocop}\\\"\\
\\\"$(pwd)/${one}"
_rubocops="${_rubocops}
watch(%r{^$(pwd)/${one}\$})"
_maybe_control_list="${_maybe_control_list}
${one}"
_found=$(( _found + 1 ))
}
done <<< "${_possible_related_classes}"
# multiple files
if [ ${_found} -gt 0 ] ; then
{
if [[ -n "${observe_one_line}" ]] ; then # Criteria: if one numeric : then pass only one test to run but keep observing other files
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${observe_one_line-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
else
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"${_files_to_rspec-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
fi
}
fi
_found=0
local __all_passed_files="$( sed 's/\.rb\ /.rb\n/g' <<< "${*-}")"
echo __all_passed_files:"${__all_passed_files}"
while read -r one ; do
{
[[ -z "${one-}" ]] && continue # skip empty lines
[[ -f "${one-}" ]] || continue # only if file exists
_ignore_ruby_list "${one}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip ignored files
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
file_to_watch="${file_to_watch}\"\\
--watch \"$(pwd)/${one}"
_files_to_rubocop="${_files_to_rubocop}\\\"\\
\\\"$(pwd)/${one}"
_rubocops="${_rubocops}
watch(%r{^$(pwd)/${one}\$})"
if ( grep -q "_spec.rb[[:space:]]*$" <<< "${one}" ) ; then
{
_is_duplicated "${one}" "${_maybe_control_list}"
_err=$?
[ ${_err} -gt 0 ] && continue # skip duplicated files
_maybe_control_list="${_maybe_control_list}
${one}"
_files_to_rspec="${_files_to_rspec}\\\"\\
\\\"$(pwd)/${one}"
}
else
{
_maybe_control_list="${_maybe_control_list}
${one}"
}
fi
_found=$(( _found + 1 ))
}
done <<< "${__all_passed_files}"
# multiple files
echo _files_to_rspec:"${_files_to_rspec}"
# DEBUG exit 0
if [ ${_found} -gt 0 ] ; then
{
if [[ -n "${observe_one_line}" ]] ; then # Criteria: if one numeric : then pass only one test to run but keep observing other files
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"$(pwd)/${observe_one_line-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
else
{
extra_args_to_run_preview="clear && bundle exec rubocop -A \\\"${_files_to_rubocop-}\\\" && FULL_SPEC_RUN=true RACK_ENV=test RAILS_ENV=test NODE_ENV=test COVERAGE=true CI_RSPEC=false bundle exec rspec --tty --color --format documentation \\\"${_files_to_rspec-}\\\" && live-server coverage "
extra_args_to_run="[[ -n \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps axt | grep 'live-server' | grep 'coverage' | head -1 | xargs | cut -d' ' -f2 )\\\" || ( ${extra_args_to_run_preview} ) && ( ${extra_args_to_run_preview} ) "
}
fi
}
fi
replacer_colors_sufix3=$(cat <<-EOF
| ${REPLACER} --unbuffered 's/"${_maybe_name2-}"/\o033[38;5;178m"${_maybe_name2-}"\o033[0m/g' \\
| ${REPLACER} --unbuffered 's/"${_maybe_name2-}"/\o033[38;5;178m"${_maybe_name2-}"\o033[0m/g' \\
EOF
)
# | ${REPLACER} --unbuffered 's@/./@/@g' \\
} # end [[ -n "${_possible_related_classes}" ]]
fi
} # end ag -l "${_maybe_name}" | grep -v '_spec.rb'
fi
} # end [[ -n "${_maybe_name}" ]]
fi
file_to_observe=""
}
else
{
# rspec no ?
prefix_to_run="[[ -n \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs)\\\" ]] || kill \\\"\$(ps aux | grep '${file_to_observe-}' | grep -v 'grep' | head -1 | xargs | cut -d' ' -f2 )\\\" || ruby \\\"$(pwd)/${file_to_observe-}\\\" && ruby "
file_to_watch="$(pwd)/${file_to_observe-}"
file_to_observe="$(pwd)/${file_to_observe-}"
}
fi
#
}
else
{
extension_to_observe="rs,py,go,bash,sh,kv,php,rb,java"
}
fi
echo " extension_to_observe:${extension_to_observe-}"
echo " _filename:${_filename-}"
echo " _script_name:${_script_name-}"
echo " prefix_to_run:${prefix_to_run-}"
echo " file_to_observe:${file_to_observe-}"
echo " file_to_watch:${file_to_watch-}"
echo " extra_args_to_run:${extra_args_to_run-}"
if [[ $REPLACERGNU == "YES" ]] ; then
{
echo '-----'
if [[ -n "${extra_args_to_run}" ]] ; then
{
# if ( bundle info guard >/dev/null 2>&1 ) ; then
# {
# cat <<-EOF > ".${_filename}.watch.test.guardfile"
# group :red_green_refactor do
# guard :rubocop, all_on_start: false, cli: ['-A'] do
# # watch(%r{^request_spec\.rb$})
# ${_rubocops}
# end
# guard :rspec, cmd: "bundle exec rspec --tty --color --format documentation" do
# # watch(%r{^request_spec\.rb$})
# ${_rpec_file}
# end
# end
# EOF
# cat <<-EOF > ".${_filename}.watch.test.bash"
# #!/usr/bin/env bash
# echo "bundle install guard guard-rubocop guard-rspec"
# bundle add guard >/dev/null 2>&1;
# bundle add guard-rubocop >/dev/null 2>&1;
# bundle add guard-rspec >/dev/null 2>&1;
# echo "bundle guard -G \"$(pwd)/.${_filename}.watch.test.guardfile\" "
# bundle exec guard -G "$(pwd)/.${_filename}.watch.test.guardfile" \
# # bundle remove guard-rubocop >/dev/null 2>&1;
# git checkout Gemfile Gemfile.lock
# EOF
# # | ${REPLACER} --unbuffered 's@/./@/@g' \
# chmod a+x ".${_filename}.watch.test.bash"
# ./".${_filename}.watch.test.bash"
# }
# }
# elif ( command -v watchman >/dev/null 2>&1; ) ; then
# {
# file_to_watch="$( ${REPLACER} 's/\-\-watch//g' <<< "${file_to_watch}" )"
# # ruby rspec observe spec/concern_spec.rb
# echo " \"${extra_args_to_run} ${file_to_observe}\" "
# # watchman watch "${file_to_observe}" trigger "${extra_args_to_run} ${file_to_observe}" 2>&1 \
# cat <<-EOF > ".${_filename}.watchman.watch.test.bash"
# ${replacer_colors_prefix}
# ${extra_args_to_run} 2>&1 \
# watchman trigger-del "$pwd_backslash_escaped_for_sed" "${_maybe_name-}"
# ${replacer_colors_sufix}
# EOF
# watchman watch \"${file_to_watch-}\"
# watchman -- trigger "$pwd_backslash_escaped_for_sed" "${_maybe_name-}" '*.rb' -- "$cwd/.${_filename}.watchman.watch.test.bash"
# # | ${REPLACER} --unbuffered 's@/./@/@g' \
# chmod a+x ".${_filename}.watchman.watch.test.bash"
# ./".${_filename}.watchman.watch.test.bash"
# }
if ( command -v nodemon >/dev/null 2>&1; ) ; then
{
# ruby rspec observe spec/concern_spec.rb
echo "nodemon --watch \"${file_to_watch-}\" --ext ${extension_to_observe} --spawn --exec \"${extra_args_to_run} ${file_to_observe}\" "
[[ -e ./".${_filename}.nodemon.watch.test.bash" ]] && rm -rf ./".${_filename}.nodemon.watch.test.bash"
# nodemon --watch "${file_to_observe}" --ext ${extension_to_observe} --spawn --exec "${extra_args_to_run} ${file_to_observe}" 2>&1 \
cat <<-EOF > ".${_filename}.nodemon.watch.test.bash"
${replacer_colors_prefix}
nodemon --watch "${file_to_watch}" \\
--ext ${extension_to_observe} \\
--spawn \\
--exec "${extra_args_to_run} ${file_to_observe}" 2>&1 \\
${replacer_colors_sufix}
${replacer_colors_sufix2}
${replacer_colors_sufix3}
EOF
# ${replacer_colors_sufix}
# ${replacer_colors_sufix2}
# | ${REPLACER} --unbuffered 's@/./@/@g' \
chmod a+x ".${_filename}.nodemon.watch.test.bash"
./".${_filename}.nodemon.watch.test.bash"
}
elif ( command -v watchexec >/dev/null 2>&1; ) ; then
{
# ruby rspec observe spec/concern_spec.rb
echo "watchexec --watch \"${file_to_watch-}\" --exts ${extension_to_observe} --restart \"${extra_args_to_run} ${file_to_observe}\" "
[[ -e ./".${_filename}.watchexec.watch.test.bash" ]] && rm -rf ./".${_filename}.watchexec.watch.test.bash"
# watchexec --watch "${file_to_observe}" --exts ${extension_to_observe} --restart "${extra_args_to_run} ${file_to_observe}" 2>&1 \
cat <<-EOF > ".${_filename}.watchexec.watch.test.bash"
${replacer_colors_prefix}
watchexec --watch "${file_to_watch}" --exts ${extension_to_observe} --restart "${extra_args_to_run} ${file_to_observe}" 2>&1 \
${replacer_colors_sufix}
${replacer_colors_sufix2}
EOF
# | ${REPLACER} --unbuffered 's@/./@/@g' \\
chmod a+x ".${_filename}.watchexec.watch.test.bash"
./".${_filename}.watchexec.watch.test.bash"
}
else
{
echo "ERROR could not find watchexec or nodemon to start
Please install either:
faster https://github.com/watchexec/watchexec
descent https://facebook.github.io/watchman/
classic https://www.npmjs.com/package/nodemon
"
exit 1
}
fi
}
# ------------
# ------------
# ------------
# ------------
# ------------
# ------------
else # prefix style
# -------------
# -------------
# -------------
# -------------
# -------------
# -------------
# -------------
{
# if ( bundle info guard >/dev/null 2>&1 ) ; then
# {
# cat <<-EOF > ".${_filename}.watch.test.guardfile"
# group :red_green_refactor do
# guard :rubocop, all_on_start: false, cli: ['-A'] do
# # watch(%r{^request_spec\.rb$})
# ${_rubocops}
# end
# guard :rspec, cmd: "bundle exec rspec --tty --color --format documentation" do
# # watch(%r{^request_spec\.rb$})
# ${_rpec_file}
# end
# end
# EOF
# cat <<-EOF > ".${_filename}.guard.watch.test.bash"
# #!/usr/bin/env bash
# echo "bundle install guard guard-rubocop guard-rspec"
# bundle add guard >/dev/null 2>&1;
# bundle add guard-rubocop >/dev/null 2>&1;
# bundle add guard-rspec >/dev/null 2>&1;
# echo "bundle guard -G \"$(pwd)/.${_filename}.watch.test.guardfile\" "
# bundle exec guard -G "$(pwd)/.${_filename}.watch.test.guardfile" \
# # bundle remove guard-rubocop >/dev/null 2>&1;
# git checkout Gemfile Gemfile.lock
# EOF
# # | ${REPLACER} --unbuffered 's@/./@/@g' \
# chmod a+x ".${_filename}.guard.watch.test.bash"
# ./".${_filename}.guard.watch.test.bash"
# }
if ( command -v watchexec >/dev/null 2>&1; ) ; then
{
# go observe homework.go
# rust observe Cargo.toml
# echo "nodemon --watch \"${file_to_watch-}\" --exts ${extension_to_observe} --restart \"${prefix_to_run-}$(pwd)/${*}\" "
echo "watchexec --watch \"./\" --exts py,go,bash,sh,kv,php,rb,java --restart \"${prefix_to_run-}$(pwd)/${*}\" "
[[ -e ./".${_filename}.watchexec.watch.test.bash" ]] && rm -rf ./".${_filename}.watchexec.watch.test.bash"
# watchexec --watch "${file_to_observe}" --exts ${extension_to_observe} --restart "${extra_args_to_run} ${file_to_observe}" 2>&1 \
cat <<-EOF > ".${_filename}.watchexec.watch.test.bash"
${replacer_colors_prefix}
watchexec --watch "./" --exts py,go,bash,sh,kv,php,rb,java --restart "${prefix_to_run-}$(pwd)/${*}" 2>&1 \
${replacer_colors_sufix}
EOF
chmod a+x ".${_filename}.watchexec.watch.test.bash"
./".${_filename}.watchexec.watch.test.bash"
# }
# elif ( command -v watchman >/dev/null 2>&1; ) ; then
# {
# file_to_watch="$( ${REPLACER} 's/\-\-watch//g' <<< "${file_to_watch}" )"
# # ruby rspec observe spec/concern_spec.rb
# echo "watchman watch \"${file_to_watch-}\" trigger \"${extra_args_to_run} ${file_to_observe}\" "
# # watchman watch "${file_to_observe}" trigger "${extra_args_to_run} ${file_to_observe}" 2>&1 \
# cat <<-EOF > ".${_filename}.watchman.watch.test.bash"
# #!/usr/bin/env bash
# pathpat="(/[^/]*)+:[0-9]+"