Skip to content

Commit 1c97dac

Browse files
committed
fix: make nodesc format work and clean up unused 'tasks' code from makefiles
1 parent 36f49f3 commit 1c97dac

File tree

9 files changed

+30
-93
lines changed

9 files changed

+30
-93
lines changed

runfile.sh

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,24 @@ function print-makefile() {
166166
sed -E "s!\tmake --makefile ${makefile} !\tmake !" "$@"
167167
}
168168

169-
function print-runfile-commands() {
169+
function print-runfile-commands() { local task_re
170+
task_re='([[:alnum:]_-][[:alnum:] _-]+):[[:alnum:] _-]*(#(.*))?'
170171
# Print current Runfile commands:
171172
echo
172-
grep -E '[[:alnum:]_-][[:alnum:] _-]+:[[:alnum:] _-]*#' "$( smartcase-file runfile )" \
173-
| sed -Ee 's/:.*#/ · /g' -e 's/ / /g' -e 's/^/ /g'
174-
# Print Runfile command aliases if any are currently available:
173+
grep -E "^${task_re}$" "$( smartcase-file runfile )" \
174+
| sed -Ee "s/^${task_re}$/\1 · \3/g" -e 's/ / /g' -e 's/^/ /g'
175175
echo
176+
# Print Runfile command aliases if any are currently available:
176177
awk 'NR==FNR{a[$0]=1;next}a[$0]' <( bash -ic 'alias' ) <( print-runfile-aliases ) \
177178
| sed -e "s/\'/ /g" -e "s/= / · /" -e 's/^/ /' -e 's/$/\n/' \
178179
| perl -0777 -pe 's/\n\n(.)/\n\1/g'
179180
}
180181

181182
function print-runfile-aliases() {
183+
task_re='([[:alnum:]_-][[:alnum:] _-]+):[[:alnum:] _-]*(#(.*))?'
182184
echo '# Runfile Aliases'
183-
grep -E '[[:alnum:]_-][[:alnum:] _-]+:[[:alnum:] _-]*#' "$( smartcase-file runfile )" \
184-
| sed -E 's/.*(^| )([[:alnum:]_-][[:alnum:]_-]+):.*/\2/g' \
185+
grep -E "^${task_re}$" "$( smartcase-file runfile )" \
186+
| sed -E "s/.*(^| )${task_re}$/\2/g" \
185187
| awk '!_[substr($1,1,1)]++' `# unique on first char of each command` \
186188
| sed -E "s/(.)(.*)/alias ${RUNFILE_ALIASES_PREFIX:-r}\1='run \1\2'/"
187189
echo '# END Runfile Aliases'
@@ -403,11 +405,11 @@ EOF
403405
}
404406

405407
function run() ( set -euo pipefail
406-
local makefile='' buffer='' task='' baseindent='' tab=$'\t'
408+
local makefile='' buffer='' task='' baseindent=''
407409
local arg='' make_args=() named_args=() pos_args=() pos_arg_idx=0
408410

409411
local runfile_variables='' runfile_variable_re='' run_arg_re=''
410-
local task_re='' trap_re='' vbse_re_1='' vbse_re_2=''
412+
local task_re='' trap_re=''
411413
local trap_sig='' runfile_grep_filter_args=()
412414

413415
run_arg_re='-([hvrmena]|-(help|version|runfile|makefile|edit|new|alias|eject|verbose|compact|compat|noconfirm|noedit))'
@@ -507,26 +509,17 @@ function run() ( set -euo pipefail
507509
fi
508510
done
509511
510-
# If --verbose specified, use modified patterns for Makefile .tasks list so
511-
# that when each task is printed, its commands are printed line-by-line underneath:
512-
if [[ " $* " == *' --verbose '* ]] \
513-
|| [[ "${RUNFILE_VERBOSE:-}" =~ ^(1|true|TRUE|True)$ ]]
514-
then
515-
vbse_re_1='\\s+|'
516-
vbse_re_2='s/^([^[:space:]])/\\n\\1/g'
517-
fi
518-
519-
task_re='([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#'
512+
task_re='([[:alnum:]_-][[:alnum:] _-]+):([[:alnum:] _-]+)?(#.*)?'
520513
trap_re='(EXIT|HUP|INT|QUIT|ABRT|KILL|ALRM|TERM)'
521514
522515
if [[ "${RUNFILE_TRAP:-}" == '*' ]]
523516
then
524-
runfile_grep_filter_args=( -E "^(${task_re}|\\s*${trap_re})" )
517+
runfile_grep_filter_args=( -E "^(${task_re}|\s*${trap_re} .*)$" )
525518
elif [[ -n "${RUNFILE_TRAP:-}" ]]
526519
then
527-
runfile_grep_filter_args=( -E "^(${task_re}|\\s*${RUNFILE_TRAP})" )
520+
runfile_grep_filter_args=( -E "^(${task_re}|\s*${RUNFILE_TRAP} .*)$" )
528521
else
529-
runfile_grep_filter_args=( -Ev "^\s*${trap_re}" )
522+
runfile_grep_filter_args=( -Ev "^\s*${trap_re} .*$" )
530523
fi
531524
532525
if [[ -n "${RUNFILE_SKIP_SUBTASKS:-}" ]]
@@ -556,9 +549,7 @@ function run() ( set -euo pipefail
556549
cat <<EOF> "${makefile}"
557550
SHELL = ${SHELL:-bash}
558551
559-
${runfile_variables}.PHONY: _tasks
560-
_tasks: .tasks
561-
$(
552+
${runfile_variables}$(
562553
grep "${runfile_grep_filter_args[@]}" "$( smartcase-file runfile )" \
563554
| grep -Ev "${runfile_variable_re}" \
564555
| sed -E \
@@ -572,7 +563,7 @@ $(
572563
`# prefix every line with TAB` \
573564
-e "s!^\t\$!!" \
574565
`# remove TAB from blank lines` \
575-
-e "s!^\t${task_re}(.*)\$!\n.PHONY: \1\n\1:${subtask_re}\#\3!" \
566+
-e "s!^\t${task_re}(.*)\$!\n.PHONY: \1\n\1:${subtask_re}\3!" \
576567
`# remove TAB-prefix from lines that match task pattern` \
577568
`# Improve Make's default handling of multiline statements (if, for, while):` \
578569
-e "s!^\t\t(.*;[[:space:]]*[^\\]?)\$!\t\t\1 \\\\!" \
@@ -588,11 +579,6 @@ $(
588579
`# add backslash after "then", "else", "do" when on their own line` \
589580
| cat -s
590581
)
591-
592-
.PHONY: .tasks
593-
.tasks:
594-
${tab}grep -E "^(${vbse_re_1}${task_re})" \$(MAKEFILE_LIST) \\
595-
${tab}| sed -Ee "${vbse_re_2:-s/^/ /}" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'
596582
EOF
597583
598584
# Done with temporary Makefile construction.

tests/2space/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -181,8 +179,3 @@ complex: # a sample command exploring complex multiline syntax
181179
then x='hjkl'; echo -n " $${x} ::"; \
182180
else echo -n " $${x} ::"; \
183181
fi
184-
185-
.PHONY: .tasks
186-
.tasks:
187-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/3space/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -181,8 +179,3 @@ complex: # a sample command exploring complex multiline syntax
181179
then x='hjkl'; echo -n " $${x} ::"; \
182180
else echo -n " $${x} ::"; \
183181
fi
184-
185-
.PHONY: .tasks
186-
.tasks:
187-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/4space/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -181,8 +179,3 @@ complex: # a sample command exploring complex multiline syntax
181179
then x='hjkl'; echo -n " $${x} ::"; \
182180
else echo -n " $${x} ::"; \
183181
fi
184-
185-
.PHONY: .tasks
186-
.tasks:
187-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/8space/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -181,8 +179,3 @@ complex: # a sample command exploring complex multiline syntax
181179
then x='hjkl'; echo -n " $${x} ::"; \
182180
else echo -n " $${x} ::"; \
183181
fi
184-
185-
.PHONY: .tasks
186-
.tasks:
187-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/compact/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -158,8 +156,3 @@ complex: # a sample command exploring complex multiline syntax
158156
then x='hjkl'; echo -n " $${x} ::"; \
159157
else echo -n " $${x} ::"; \
160158
fi
161-
162-
.PHONY: .tasks
163-
.tasks:
164-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
165-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/nodesc/Makefile

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
7-
start:stop#
5+
start:stop
86
run build env=dev
97
echo "starting app"
108
run loading
119

1210
.PHONY: stop
13-
stop:#
11+
stop:
1412
echo "stopping app"
1513

1614
.PHONY: loading
17-
loading:#
15+
loading:
1816
if [[ $(@) == '--fin' ]]; \
1917
then \
2018
echo "loading finished"; \
@@ -23,20 +21,20 @@ loading:#
2321
fi
2422

2523
.PHONY: build
26-
build:lint#
24+
build:lint
2725
[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
2826

2927
.PHONY: test
30-
test:#
28+
test:
3129
run build env=test
3230
[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
3331

3432
.PHONY: lint
35-
lint:#
33+
lint:
3634
[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
3735

3836
.PHONY: complex
39-
complex:#
37+
complex:
4038
echo "--- for loops ---"
4139
for x in abc hjkl xyz; \
4240
do \
@@ -158,8 +156,3 @@ complex:#
158156
then x='hjkl'; echo -n " $${x} ::"; \
159157
else echo -n " $${x} ::"; \
160158
fi
161-
162-
.PHONY: .tasks
163-
.tasks:
164-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
165-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

tests/nodesc/Runfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
start:stop#
1+
start:stop
22
run build env=dev
33
echo "starting app"
44
run loading
55
EXIT run loading --fin
66
INT run loading --fin
7-
stop:#
7+
stop:
88
HUP run loading --fin
99
echo "stopping app"
10-
loading:#
10+
loading:
1111
if [[ $(@) == '--fin' ]]
1212
then
1313
echo "loading finished"
1414
else
1515
echo "loading started"
1616
fi
17-
build:lint#
17+
build:lint
1818
[[ -n $(env) ]] && echo "buiding app for $(env)" || echo "error: missing env"
19-
test:#
19+
test:
2020
run build env=test
2121
[[ -n $(@) ]] && echo "running tests $(@)" || echo "running all tests"
22-
lint:#
22+
lint:
2323
[[ -n $(1) ]] && echo "linting file $(1)" || echo "linting all files"
24-
complex:#
24+
complex:
2525
echo "--- for loops ---"
2626
for x in abc hjkl xyz
2727
do

tests/tabbed/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
SHELL = /bin/bash
22

3-
.PHONY: _tasks
4-
_tasks: .tasks
53

64
.PHONY: start
75
start: stop # start app
@@ -181,8 +179,3 @@ complex: # a sample command exploring complex multiline syntax
181179
then x='hjkl'; echo -n " $${x} ::"; \
182180
else echo -n " $${x} ::"; \
183181
fi
184-
185-
.PHONY: .tasks
186-
.tasks:
187-
grep -E "^(([[:alnum:]_-][[:alnum:][:space:]_-]+):([[:alnum:][:space:]_-]+)?#)" $(MAKEFILE_LIST) \
188-
| sed -Ee "s/^/ /" -e 's/[[:space:]]*:[[:alnum:] _-]*#[[:space:]]*/ · /'

0 commit comments

Comments
 (0)