@@ -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
181182function 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
405407function 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
556549cat <<EOF> " ${makefile} "
557550SHELL = ${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 \
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 \\\\ !" \
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:]]*/ · /'
596582EOF
597583
598584# Done with temporary Makefile construction.
0 commit comments