From 031e38a0aa72f3cd302e95f98c0aa64ae52d3c66 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Tue, 20 Sep 2022 11:08:47 -0500 Subject: [PATCH] refactor: improve namespace --- src/builtins.mk | 2 +- src/runners.mk | 24 ++++++++++++------------ task.mk | 28 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/builtins.mk b/src/builtins.mk index bac6510..2684ebb 100644 --- a/src/builtins.mk +++ b/src/builtins.mk @@ -1,4 +1,4 @@ -# ---- [buitlin recipes] ---- # +# ---- [builtin recipes] ---- # ## h, help | show this help .PHONY: help h help h: diff --git a/src/runners.mk b/src/runners.mk index e1710a6..29a97e5 100644 --- a/src/runners.mk +++ b/src/runners.mk @@ -1,24 +1,24 @@ # ---- [python/bash script runner] ---- # ###-- modified from https://unix.stackexchange.com/a/223093 -### -define \n +define _newline endef -escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) -escape_printf = $(subst \,\\,$(subst %,%%,$1)) -create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) -printline = printf -- "<----------------------------------->\n" +_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) +_escape_printf = $(subst \,\\,$(subst %,%%,$1)) +_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1))) +_printline = printf -- "<----------------------------------->\n" ifdef DEBUG define _debug_runner -@printf "$(1) Script:\n";$(printline); -@printf "$(call create_string,$(3))\n" | cat -n -@$(printline) -@printf "$(call create_string,$(3))" | $(2) +@printf "$(1) Script:\n";$(_printline); +@printf "$(call _create_string,$(3))\n" | cat -n +@$(_printline) +@printf "$(call _create_string,$(3))" | $(2) endef py = $(call _debug_runner,Python,python3,$($(1))) tbash = $(call _debug_runner,Bash,bash,$($(1))) else -py = @python3 <(printf "$(call create_string,$($(1)))") -tbash = @bash <(printf "$(call create_string,$($(1)))") +py = @python3 <(printf "$(call _create_string,$($(1)))") +tbash = @bash <(printf "$(call _create_string,$($(1)))") endif -pysh = python3 <(printf "$(call create_string,$($(1)))") +pysh = python3 <(printf "$(call _create_string,$($(1)))") diff --git a/task.mk b/task.mk index ca6b2c4..e355719 100644 --- a/task.mk +++ b/task.mk @@ -1,7 +1,7 @@ # }> [github.com/daylinmorgan/task.mk] <{ # # Copyright (c) 2022 Daylin Morgan # MIT License -# version: 22.9.19 +# version: v22.9.19-1-g584879b-dev # # task.mk should be included at the bottom of your Makefile with `-include .task.mk` # See below for the standard configuration options that should be set prior to including this file. @@ -18,7 +18,7 @@ HELP_SEP ?= │ # python f-string literals EPILOG ?= USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make \n -# ---- [buitlin recipes] ---- # +# ---- [builtin recipes] ---- # ## h, help | show this help .PHONY: help h help h: @@ -48,28 +48,28 @@ _update-task.mk: curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk export MAKEFILE_LIST # ---- [python/bash script runner] ---- # -define \n +define _newline endef -escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) -escape_printf = $(subst \,\\,$(subst %,%%,$1)) -create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1))) -printline = printf -- "<----------------------------------->\n" +_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) +_escape_printf = $(subst \,\\,$(subst %,%%,$1)) +_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1))) +_printline = printf -- "<----------------------------------->\n" ifdef DEBUG define _debug_runner -@printf "$(1) Script:\n";$(printline); -@printf "$(call create_string,$(3))\n" | cat -n -@$(printline) -@printf "$(call create_string,$(3))" | $(2) +@printf "$(1) Script:\n";$(_printline); +@printf "$(call _create_string,$(3))\n" | cat -n +@$(_printline) +@printf "$(call _create_string,$(3))" | $(2) endef py = $(call _debug_runner,Python,python3,$($(1))) tbash = $(call _debug_runner,Bash,bash,$($(1))) else -py = @python3 <(printf "$(call create_string,$($(1)))") -tbash = @bash <(printf "$(call create_string,$($(1)))") +py = @python3 <(printf "$(call _create_string,$($(1)))") +tbash = @bash <(printf "$(call _create_string,$($(1)))") endif -pysh = python3 <(printf "$(call create_string,$($(1)))") +pysh = python3 <(printf "$(call _create_string,$($(1)))") # ---- [python scripts] ---- # define help_py import argparse