Compare commits

..

No commits in common. "e608a90b5a4c47bd0e6f937ae8c5a5399a3adca5" and "77e76edd162830abb3252f257ff30d1109ae2a9a" have entirely different histories.

18 changed files with 326 additions and 461 deletions

View file

@ -24,7 +24,7 @@ Current Features:
- custom print function - custom print function
- confirmation prompt - confirmation prompt
Depends on `GNU Make`, obviously and `Python >=3.7`, and `bash` (or `zsh`). Depends on `GNU Make`, obviously and `Python >=3.7`.
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile. Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
I agree, all you need is one file [`.task.mk`](./task.mk). I agree, all you need is one file [`.task.mk`](./task.mk).

View file

@ -9,7 +9,7 @@ all: $(CASTS)
%/demo.cast: %/record.sh %/demo.cast: %/record.sh
asciinema rec --cols $(COLS) --rows $(ROWS) --overwrite -c $< $@ asciinema rec --cols $(COLS) --rows $(ROWS) --overwrite -c $< $@
check/demo.cast: COLS = 48 check/demo.cast: COLS = 45
check/demo.cast: ROWS = 12 check/demo.cast: ROWS = 12
clean: clean:

View file

@ -11,6 +11,6 @@ define USAGE
interactivity w/ task.mk\n interactivity w/ task.mk\n
endef endef
.DEFAULT_GOAL = help .DEFUALT_GOAL = help
include $(shell git rev-parse --show-toplevel)/task.mk include $(shell git rev-parse --show-toplevel)/task.mk

View file

@ -1,129 +1,130 @@
{"version": 2, "width": 48, "height": 12, "timestamp": 1663712361, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}} {"version": 2, "width": 45, "height": 12, "timestamp": 1663509712, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
[0.008114, "o", "\u001b[H\u001b[2J\u001b[3J"] [0.007004, "o", "\u001b[H\u001b[2J\u001b[3J"]
[0.00852, "o", "bash >> "] [0.007499, "o", "bash >> "]
[0.008755, "o", "m"] [0.007695, "o", "m"]
[0.189398, "o", "a"] [0.188475, "o", "a"]
[0.279744, "o", "k"] [0.278605, "o", "k"]
[0.369775, "o", "e"] [0.368932, "o", "e"]
[0.459919, "o", " -"] [0.459055, "o", " -"]
[0.549908, "o", "f"] [0.549199, "o", "f"]
[0.639982, "o", " "] [0.639392, "o", " "]
[0.730339, "o", "c"] [0.729414, "o", "c"]
[0.820338, "o", "h"] [0.81952, "o", "h"]
[0.910414, "o", "ec"] [0.909732, "o", "ec"]
[1.090651, "o", "k"] [1.090009, "o", "k"]
[1.18077, "o", "/"] [1.180084, "o", "/"]
[1.271098, "o", "c"] [1.270256, "o", "c"]
[1.361098, "o", "h"] [1.360329, "o", "h"]
[1.451216, "o", "ec"] [1.450517, "o", "ec"]
[1.541276, "o", "k"] [1.540604, "o", "k"]
[1.631388, "o", "."] [1.630898, "o", "."]
[1.721603, "o", "m"] [1.72087, "o", "m"]
[1.811718, "o", "k"] [1.811036, "o", "k"]
[1.992079, "o", " h"] [1.991393, "o", " h"]
[2.082138, "o", "e"] [2.081431, "o", "e"]
[2.172379, "o", "l"] [2.171549, "o", "l"]
[2.262403, "o", "p"] [2.261684, "o", "p"]
[2.352473, "o", "\r\n"] [2.351833, "o", "\r\n"]
[3.381969, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\tinteractivity w/ task.mk\r\n\r\n\u001b[1;33m check\u001b[0m │ \u001b[2mget user confirmation or exit\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"] [3.373753, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\tinteractivity w/ task.mk\r\n\r\n\u001b[1;33m check\u001b[0m │ \u001b[2mget user confirmation or exit\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
[5.387545, "o", "\u001b[H\u001b[2J\u001b[3J"] [5.378629, "o", "\u001b[H\u001b[2J\u001b[3J"]
[5.387892, "o", "bash >> "] [5.37884, "o", "bash >> "]
[5.390047, "o", "m"] [5.380877, "o", "m"]
[5.570645, "o", "a"] [5.561187, "o", "a"]
[5.660579, "o", "k"] [5.651259, "o", "k"]
[5.750852, "o", "e"] [5.741367, "o", "e"]
[5.841071, "o", " -"] [5.83161, "o", " -"]
[5.931225, "o", "f"] [5.921765, "o", "f"]
[6.021286, "o", " "] [6.011971, "o", " "]
[6.111373, "o", "c"] [6.102115, "o", "c"]
[6.201586, "o", "h"] [6.192388, "o", "h"]
[6.291778, "o", "ec"] [6.282346, "o", "ec"]
[6.472054, "o", "k"] [6.462683, "o", "k"]
[6.562124, "o", "/"] [6.552812, "o", "/"]
[6.652262, "o", "c"] [6.642847, "o", "c"]
[6.74248, "o", "h"] [6.73297, "o", "h"]
[6.832675, "o", "ec"] [6.823099, "o", "ec"]
[6.922668, "o", "k"] [6.913297, "o", "k"]
[7.012809, "o", "."] [7.003515, "o", "."]
[7.102973, "o", "m"] [7.093594, "o", "m"]
[7.193151, "o", "k"] [7.183719, "o", "k"]
[7.373458, "o", " c"] [7.364474, "o", " c"]
[7.463783, "o", "h"] [7.454638, "o", "h"]
[7.553761, "o", "e"] [7.544856, "o", "e"]
[7.643931, "o", "c"] [7.634908, "o", "c"]
[7.734197, "o", "k"] [7.725037, "o", "k"]
[7.824356, "o", "\r\n"] [7.815191, "o", "\r\n"]
[8.857505, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "] [8.827899, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
[9.54018, "o", "y"] [9.751154, "o", "y"]
[9.595198, "o", "\r\n"] [9.837618, "o", "\r\n"]
[9.598684, "o", "you said yes!\r\n"] [9.846779, "o", "you said yes!\r\n"]
[11.602689, "o", "#"] [11.850338, "o", "#"]
[11.783071, "o", " "] [12.030527, "o", " "]
[11.873235, "o", "L"] [12.12062, "o", "L"]
[11.963465, "o", "e"] [12.210763, "o", "e"]
[12.053444, "o", "t'"] [12.300857, "o", "t'"]
[12.143548, "o", "s"] [12.391099, "o", "s"]
[12.233881, "o", " "] [12.481244, "o", " "]
[12.323915, "o", "t"] [12.57145, "o", "t"]
[12.41414, "o", "r"] [12.66148, "o", "r"]
[12.50428, "o", "y "] [12.751606, "o", "y "]
[12.684471, "o", "a"] [12.932134, "o", "a"]
[12.774773, "o", "g"] [13.022101, "o", "g"]
[12.864864, "o", "a"] [13.112244, "o", "a"]
[12.954989, "o", "i"] [13.202336, "o", "i"]
[13.045011, "o", "n "] [13.292469, "o", "n "]
[13.135204, "o", "b"] [13.38261, "o", "b"]
[13.225451, "o", "u"] [13.472767, "o", "u"]
[13.315649, "o", "t"] [13.562841, "o", "t"]
[13.405687, "o", " "] [13.652944, "o", " "]
[13.585943, "o", "in"] [13.833164, "o", "in"]
[13.676051, "o", "s"] [13.923274, "o", "s"]
[13.766346, "o", "t"] [14.013422, "o", "t"]
[13.856324, "o", "e"] [14.10364, "o", "e"]
[13.946542, "o", "a"] [14.193783, "o", "a"]
[14.036697, "o", "d "] [14.283859, "o", "d "]
[14.126782, "o", "s"] [14.374022, "o", "s"]
[14.216944, "o", "a"] [14.464304, "o", "a"]
[14.307128, "o", "y"] [14.554416, "o", "y"]
[14.487468, "o", " "] [14.734528, "o", " "]
[14.577551, "o", "no"] [14.824636, "o", "no"]
[14.667739, "o", " "] [14.914924, "o", " "]
[14.757899, "o", "t"] [15.005102, "o", "t"]
[14.848007, "o", "h"] [15.095117, "o", "h"]
[14.93806, "o", "i"] [15.185276, "o", "i"]
[15.0283, "o", "s "] [15.275414, "o", "s "]
[15.118379, "o", "t"] [15.365521, "o", "t"]
[15.208471, "o", "i"] [15.45574, "o", "i"]
[15.388757, "o", "m"] [15.635918, "o", "m"]
[15.47897, "o", "e"] [15.726033, "o", "e"]
[15.569031, "o", "\r\n"] [15.816169, "o", "\r\n"]
[16.571969, "o", "\u001b[H\u001b[2J\u001b[3J"] [16.817697, "o", "\u001b[H\u001b[2J\u001b[3J"]
[16.572047, "o", "bash >> "] [16.817793, "o", "bash >> "]
[16.574017, "o", "m"] [16.818364, "o", "m"]
[16.754499, "o", "a"] [16.999104, "o", "a"]
[16.844612, "o", "k"] [17.089183, "o", "k"]
[16.93468, "o", "e"] [17.179376, "o", "e"]
[17.024972, "o", " -"] [17.269421, "o", " -"]
[17.115137, "o", "f"] [17.359516, "o", "f"]
[17.205244, "o", " "] [17.449715, "o", " "]
[17.295415, "o", "c"] [17.539785, "o", "c"]
[17.385554, "o", "h"] [17.629954, "o", "h"]
[17.475882, "o", "ec"] [17.720065, "o", "ec"]
[17.655989, "o", "k"] [17.900294, "o", "k"]
[17.746279, "o", "/"] [17.990472, "o", "/"]
[17.83643, "o", "c"] [18.080485, "o", "c"]
[17.926644, "o", "h"] [18.170674, "o", "h"]
[18.016673, "o", "ec"] [18.260717, "o", "ec"]
[18.106718, "o", "k"] [18.350924, "o", "k"]
[18.197045, "o", "."] [18.441115, "o", "."]
[18.287031, "o", "m"] [18.531291, "o", "m"]
[18.377151, "o", "k"] [18.621449, "o", "k"]
[18.55735, "o", " c"] [18.801717, "o", " c"]
[18.647478, "o", "h"] [18.891834, "o", "h"]
[18.737616, "o", "e"] [18.982112, "o", "e"]
[18.827879, "o", "c"] [19.07216, "o", "c"]
[18.917992, "o", "k"] [19.162471, "o", "k"]
[19.008133, "o", "\r\n"] [19.252562, "o", "\r\n"]
[20.034923, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "] [20.265973, "o", "Would you like to proceed? \u001b[1;31m[Y/n]\u001b[0m "]
[22.08808, "o", "n"] [21.947847, "o", "n"]
[22.227223, "o", "\r\n"] [22.001462, "o", "\r\n"]
[22.00656, "o", "make[1]: *** [check/check.mk:8: check] Error 1\r\n"]

View file

@ -7,4 +7,4 @@ cmd 'make -f check/check.mk check'
msg "# Let's try again but instead say no this time" msg "# Let's try again but instead say no this time"
cmd 'make -f check/check.mk check' cmd 'make -f check/check.mk check'
sleep 1

View file

@ -1,126 +1,125 @@
{"version": 2, "width": 60, "height": 20, "timestamp": 1663712193, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}} {"version": 2, "width": 60, "height": 20, "timestamp": 1663509736, "env": {"SHELL": "/usr/bin/zsh", "TERM": "xterm-256color"}}
[0.008386, "o", "\u001b[H\u001b[2J\u001b[3J"] [0.006995, "o", "\u001b[H\u001b[2J\u001b[3J"]
[0.008986, "o", "bash >> "] [0.007356, "o", "bash >> "]
[0.009151, "o", "m"] [0.007626, "o", "m"]
[0.189701, "o", "a"] [0.188158, "o", "a"]
[0.280162, "o", "k"] [0.27839, "o", "k"]
[0.37038, "o", "e"] [0.368576, "o", "e"]
[0.460683, "o", " -"] [0.458807, "o", " -"]
[0.551001, "o", "f"] [0.548811, "o", "f"]
[0.641267, "o", " "] [0.63903, "o", " "]
[0.731609, "o", "e"] [0.729091, "o", "e"]
[0.821777, "o", "m"] [0.819196, "o", "m"]
[0.912103, "o", "be"] [0.909274, "o", "be"]
[1.092658, "o", "d"] [1.089691, "o", "d"]
[1.182705, "o", "d"] [1.179663, "o", "d"]
[1.273152, "o", "e"] [1.269774, "o", "e"]
[1.363457, "o", "d"] [1.359973, "o", "d"]
[1.453758, "o", "/e"] [1.450027, "o", "/e"]
[1.544059, "o", "m"] [1.540296, "o", "m"]
[1.634282, "o", "b"] [1.630272, "o", "b"]
[1.724452, "o", "e"] [1.720364, "o", "e"]
[1.814601, "o", "d"] [1.8106, "o", "d"]
[1.995155, "o", "de"] [1.990776, "o", "de"]
[2.085437, "o", "d"] [2.080964, "o", "d"]
[2.175546, "o", "."] [2.17101, "o", "."]
[2.265856, "o", "m"] [2.261109, "o", "m"]
[2.356192, "o", "k"] [2.351249, "o", "k"]
[2.446468, "o", " h"] [2.441359, "o", " h"]
[2.536781, "o", "e"] [2.531512, "o", "e"]
[2.627101, "o", "l"] [2.621795, "o", "l"]
[2.717423, "o", "p"] [2.711889, "o", "p"]
[2.897934, "o", "\r\n"] [2.892394, "o", "\r\n"]
[3.931131, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\texamples of embedded scripts in `\u001b[35mMakefile\u001b[0m`\r\n\r\n \u001b[1;31m examples of task.mk features \u001b[0m\r\n\u001b[38m ─────────────────────────────────────────────────────\u001b[0m\r\n\u001b[1;33m list-%\u001b[0m │ \u001b[2muse pathlib.Path to list files\u001b[0m\r\n \u001b[2mname the directory in rule (make list-src)\u001b[0m\r\n\u001b[1;33m embedded-bash\u001b[0m │ \u001b[2mbash script with pipes and make input\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"] [3.915806, "o", "\u001b[1;36musage:\u001b[0m\r\n\tmake <recipe>\r\n\t\r\n\texamples of embedded scripts in `\u001b[35mMakefile\u001b[0m`\r\n\r\n \u001b[1;31m examples of task.mk features \u001b[0m\r\n\u001b[38m ─────────────────────────────────────────────────────\u001b[0m\r\n\u001b[1;33m list-%\u001b[0m │ \u001b[2muse pathlib.Path to list files\u001b[0m\r\n \u001b[2mname the directory in rule (make list-src)\u001b[0m\r\n\u001b[1;33m embedded-bash\u001b[0m │ \u001b[2mbash script with pipes and make input\u001b[0m\r\n\u001b[1;33m h, help\u001b[0m │ \u001b[2mshow this help\u001b[0m\r\n\r\n"]
[5.936874, "o", "\u001b[H\u001b[2J\u001b[3J"] [5.921614, "o", "\u001b[H\u001b[2J\u001b[3J"]
[5.937167, "o", "bash >> "] [5.921918, "o", "bash >> "]
[5.939502, "o", "m"] [5.923943, "o", "m"]
[6.120169, "o", "a"] [6.104382, "o", "a"]
[6.210505, "o", "k"] [6.194681, "o", "k"]
[6.300671, "o", "e"] [6.284819, "o", "e"]
[6.390788, "o", " -"] [6.375089, "o", " -"]
[6.480981, "o", "f"] [6.465174, "o", "f"]
[6.571285, "o", " "] [6.555322, "o", " "]
[6.661457, "o", "e"] [6.64533, "o", "e"]
[6.751758, "o", "m"] [6.735435, "o", "m"]
[6.842048, "o", "be"] [6.825552, "o", "be"]
[7.022576, "o", "d"] [7.005939, "o", "d"]
[7.112852, "o", "d"] [7.096066, "o", "d"]
[7.203064, "o", "e"] [7.186097, "o", "e"]
[7.293421, "o", "d"] [7.276232, "o", "d"]
[7.383397, "o", "/e"] [7.366364, "o", "/e"]
[7.473873, "o", "m"] [7.456527, "o", "m"]
[7.564152, "o", "b"] [7.546662, "o", "b"]
[7.65431, "o", "e"] [7.636777, "o", "e"]
[7.744607, "o", "d"] [7.726911, "o", "d"]
[7.925168, "o", "de"] [7.907171, "o", "de"]
[8.015472, "o", "d"] [7.99733, "o", "d"]
[8.105767, "o", "."] [8.087458, "o", "."]
[8.195936, "o", "m"] [8.177539, "o", "m"]
[8.286184, "o", "k"] [8.26767, "o", "k"]
[8.376537, "o", " l"] [8.357795, "o", " l"]
[8.466624, "o", "i"] [8.447911, "o", "i"]
[8.557058, "o", "s"] [8.538022, "o", "s"]
[8.64739, "o", "t"] [8.628232, "o", "t"]
[8.827942, "o", "-"] [8.80841, "o", "-"]
[8.91803, "o", "em"] [8.898543, "o", "em"]
[9.008446, "o", "b"] [8.988721, "o", "b"]
[9.098742, "o", "e"] [9.078836, "o", "e"]
[9.189059, "o", "d"] [9.169069, "o", "d"]
[9.279328, "o", "d"] [9.259138, "o", "d"]
[9.36965, "o", "ed"] [9.349222, "o", "ed"]
[9.459574, "o", "\r\n"] [9.439533, "o", "\r\n"]
[10.492826, "o", "files in embedded\r\n"] [10.45661, "o", "files in embedded\r\n['embedded.mk', 'demo.cast', 'record.sh', 'index.md']\r\n"]
[10.492943, "o", "['embedded.mk', 'demo.cast', 'record.sh', 'index.md']\r\n"] [12.462317, "o", "\u001b[H\u001b[2J\u001b[3J"]
[12.498865, "o", "\u001b[H\u001b[2J\u001b[3J"] [12.462399, "o", "bash >> "]
[12.498984, "o", "bash >> "] [12.464413, "o", "m"]
[12.501382, "o", "m"] [12.644851, "o", "a"]
[12.681906, "o", "a"] [12.73513, "o", "k"]
[12.7722, "o", "k"] [12.825178, "o", "e"]
[12.862501, "o", "e"] [12.91541, "o", " -"]
[12.952783, "o", " -"] [13.005446, "o", "f"]
[13.043086, "o", "f"] [13.095515, "o", " "]
[13.13339, "o", " "] [13.185598, "o", "e"]
[13.223546, "o", "e"] [13.275797, "o", "m"]
[13.313887, "o", "m"] [13.365927, "o", "be"]
[13.40413, "o", "be"] [13.54612, "o", "d"]
[13.584464, "o", "d"] [13.636273, "o", "d"]
[13.674721, "o", "d"] [13.726372, "o", "e"]
[13.764931, "o", "e"] [13.81653, "o", "d"]
[13.855143, "o", "d"] [13.906755, "o", "/e"]
[13.945476, "o", "/e"] [13.996972, "o", "m"]
[14.035801, "o", "m"] [14.08711, "o", "b"]
[14.126086, "o", "b"] [14.177238, "o", "e"]
[14.216402, "o", "e"] [14.267423, "o", "d"]
[14.306688, "o", "d"] [14.447699, "o", "de"]
[14.487263, "o", "de"] [14.537782, "o", "d"]
[14.577566, "o", "d"] [14.627908, "o", "."]
[14.667572, "o", "."] [14.718053, "o", "m"]
[14.757974, "o", "m"] [14.808215, "o", "k"]
[14.848201, "o", "k"] [14.898357, "o", " e"]
[14.938383, "o", " e"] [14.988612, "o", "m"]
[15.02867, "o", "m"] [15.078745, "o", "b"]
[15.118961, "o", "b"] [15.168911, "o", "e"]
[15.2091, "o", "e"] [15.349036, "o", "d"]
[15.38968, "o", "d"] [15.439167, "o", "de"]
[15.479924, "o", "de"] [15.529412, "o", "d"]
[15.570276, "o", "d"] [15.619518, "o", "-"]
[15.66027, "o", "-"] [15.709569, "o", "b"]
[15.750729, "o", "b"] [15.79969, "o", "a"]
[15.84091, "o", "a"] [15.889938, "o", "sh"]
[15.931277, "o", "sh"] [15.980073, "o", "\r\n"]
[16.021429, "o", "\r\n"] [16.989864, "o", "Is the process running bash? We can check with ps\r\n"]
[17.044626, "o", "Is the process running bash? We can check with ps\r\n"] [16.999039, "o", "bash\r\n"]
[17.063304, "o", "bash\r\n"] [16.999517, "o", "What text to figlet? \r\n"]
[17.063756, "o", "What text to figlet? \r\n"] [19.167405, "o", "t"]
[20.107984, "o", "t"] [19.201071, "o", "a"]
[20.125262, "o", "a"] [19.292173, "o", "s"]
[20.276406, "o", "s"] [19.436959, "o", "k"]
[20.454083, "o", "k"] [19.588588, "o", "."]
[20.705234, "o", "."] [19.767086, "o", "m"]
[20.931947, "o", "m"] [19.903321, "o", "k"]
[21.010096, "o", "k"] [20.073296, "o", "\r\n"]
[21.288327, "o", "\r\n"] [20.074356, "o", " _ _ _ \r\n| |_ __ _ ___| | __ _ __ ___ | | __\r\n| __/ _` / __| |/ / | '_ ` _ \\| |/ /\r\n| || (_| \\__ \\ < _| | | | | | < \r\n \\__\\__,_|___/_|\\_(_)_| |_| |_|_|\\_\\\r\n \r\n"]
[21.292384, "o", " _ _ _ \r\n| |_ __ _ ___| | __ _ __ ___ | | __\r\n| __/ _` / __| |/ / | '_ ` _ \\| |/ /\r\n| || (_| \\__ \\ < _| | | | | | < \r\n \\__\\__,_|___/_|\\_(_)_| |_| |_|_|\\_\\\r\n \r\n"] [20.074497, "o", "the argument below as given in the makefile itself\r\n"]
[21.292754, "o", "the argument below as given in the makefile itself\r\n"] [20.074527, "o", "it's expanded before the script is passed to bash\r\n"]
[21.292898, "o", "it's expanded before the script is passed to bash\r\n"] [20.074555, "o", "bash multiline is probably working\r\n"]
[21.292925, "o", "bash multiline is probably working\r\n"]

View file

@ -38,6 +38,6 @@ define USAGE
examples of embedded scripts in `{a.magenta}Makefile{a.end}` examples of embedded scripts in `{a.magenta}Makefile{a.end}`
endef endef
.DEFAULT_GOAL = help .DEFUALT_GOAL = help
include $(shell git rev-parse --show-toplevel)/task.mk include $(shell git rev-parse --show-toplevel)/task.mk

View file

@ -5,4 +5,3 @@ source "$(dirname "${BASH_SOURCE[0]}")/../functions.sh"
cmd 'make -f embedded/embedded.mk help' cmd 'make -f embedded/embedded.mk help'
cmd 'make -f embedded/embedded.mk list-embedded' cmd 'make -f embedded/embedded.mk list-embedded'
cmd 'make -f embedded/embedded.mk embedded-bash' cmd 'make -f embedded/embedded.mk embedded-bash'

View file

@ -20,7 +20,7 @@ Current Features:
- custom print function - custom print function
- confirmation prompt - confirmation prompt
Depends on `GNU Make`, obviously and `Python >=3.7`, and `bash` (or `zsh`). Depends on `GNU Make`, obviously and `Python >=3.7`.
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile. Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
I agree, all you need is one file [`.task.mk`](https://github.com/daylinmorgan/task.mk/v22.9.19/task.mk). I agree, all you need is one file [`.task.mk`](https://github.com/daylinmorgan/task.mk/v22.9.19/task.mk).

View file

@ -56,19 +56,23 @@ See this project's `make info` for an example.
You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`. You can quickly customize some of the default behavior of `task.mk` by overriding the below variables prior to the `-include .task.mk`.
```make ```make
# ---- [config] ---- # # ---- CONFIG ---- #
HEADER_STYLE ?= b_cyan HEADER_STYLE ?= b_cyan
PARAMS_STYLE ?= b_magenta
ACCENT_STYLE ?= b_yellow ACCENT_STYLE ?= b_yellow
PARAMS_STYLE ?= $(ACCENT_STYLE)
GOAL_STYLE ?= $(ACCENT_STYLE) GOAL_STYLE ?= $(ACCENT_STYLE)
MSG_STYLE ?= faint MSG_STYLE ?= faint
DIVIDER_STYLE ?= default DIVIDER_STYLE ?= default
DIVIDER ?= ─ DIVIDER ?= ─
HELP_SEP ?= │ HELP_SEP ?= │
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n define USAGE ?=
INHERIT_SHELL ?= {ansi.$(HEADER_STYLE)}usage{ansi.end}:
make <recipe>
endef
``` ```
To use a custom color for one of the predefined configuration variables specify only the custom method. To use a custom color for one of the predefined configuration variables specify only the custom method.

View file

@ -2,9 +2,10 @@
import sys import sys
from pathlib import Path from pathlib import Path
import jinja2 import jinja2
py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm", "quit_make"] py_script_names = ["help", "ansi", "info", "print-ansi", "vars", "confirm"]
def get_jinja_env(): def get_jinja_env():

View file

@ -1,8 +1,4 @@
# ---- [builtin recipes] ---- # # ---- [buitlin recipes] ---- #
ifeq (help,$(firstword $(MAKECMDGOALS)))
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
export HELP_ARGS
endif
## h, help | show this help ## h, help | show this help
.PHONY: help h .PHONY: help h
help h: help h:
@ -31,6 +27,3 @@ _update-task.mk:
$(call tprint,{a.b_cyan}Updating task.mk{a.end}) $(call tprint,{a.b_cyan}Updating task.mk{a.end})
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
export MAKEFILE_LIST export MAKEFILE_LIST
ifndef INHERIT_SHELL
SHELL := /bin/bash
endif

View file

@ -10,4 +10,3 @@ HELP_SEP ?= │
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n
INHERIT_SHELL ?=

View file

@ -5,7 +5,6 @@
import sys import sys
##- '$(ansi_py)' -## ##- '$(ansi_py)' -##
##- '$(quit_make_py)' -##
def confirm(): def confirm():
@ -21,7 +20,7 @@ def confirm():
if confirm(): if confirm():
sys.exit() sys.exit(0)
else: else:
quit_make() sys.exit(1)
#% endblock %# #% endblock %#

View file

@ -7,7 +7,6 @@ import os
import re import re
##- '$(ansi_py)' -## ##- '$(ansi_py)' -##
##- '$(quit_make_py)' -##
MaxLens = namedtuple("MaxLens", "goal msg") MaxLens = namedtuple("MaxLens", "goal msg")
@ -15,7 +14,6 @@ MaxLens = namedtuple("MaxLens", "goal msg")
pattern = re.compile( pattern = re.compile(
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$" r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
) )
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
def parseargs(argstring): def parseargs(argstring):
@ -37,59 +35,18 @@ def gen_makefile():
return makefile return makefile
def parse_help(file, hidden=False): def parse_make(file):
for line in file.splitlines(): for line in file.splitlines():
match = pattern.search(line) match = pattern.search(line)
if match: if match:
if ( if not os.getenv("SHOW_HIDDEN") and str(
not hidden match.groupdict().get("goal")
and not os.getenv("SHOW_HIDDEN") ).startswith("_"):
and str(match.groupdict().get("goal")).startswith("_")
):
pass pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield {k: v for k, v in match.groupdict().items() if v is not None}
def recipe_help_header(goal):
item = [
i
for i in list(parse_help(gen_makefile(), hidden=True))
if "goal" in i and goal == i["goal"]
]
if item:
return fmt_goal(
item[0]["goal"],
item[0]["msg"],
len(item[0]["goal"]),
item[0].get("msgargs", ""),
)
else:
return f" {ansi.style(goal,'$(GOAL_STYLE)')}:"
def parse_goal(file, goal):
goals = goal_pattern.findall(file)
matched_goal = [i for i in goals if goal in i.split()]
output = []
if matched_goal:
output.append(recipe_help_header(matched_goal[0]))
lines = file.splitlines()
loc = [n for n, l in enumerate(lines) if l.startswith(f"{matched_goal[0]}:")][0]
recipe = []
for line in lines[loc + 1 :]:
if not line.startswith("\t"):
break
recipe.append(line)
output.append(divider(max((len(l) for l in recipe)) + 5))
output.append("\n".join(recipe) + "\n")
else:
output.append(f"{ansi.b_red}ERROR{ansi.end} Failed to find goal: {goal}")
return output
def fmt_goal(goal, msg, max_goal_len, argstr): def fmt_goal(goal, msg, max_goal_len, argstr):
args = parseargs(argstr) args = parseargs(argstr)
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)" goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
@ -101,10 +58,6 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
) )
def divider(len):
return ansi.style(f" {'$(DIVIDER)'*len}", "$(DIVIDER_STYLE)")
def fmt_rawmsg(msg, argstr, maxlens): def fmt_rawmsg(msg, argstr, maxlens):
args = parseargs(argstr) args = parseargs(argstr)
lines = [] lines = []
@ -121,7 +74,12 @@ def fmt_rawmsg(msg, argstr, maxlens):
else: else:
lines.append(f" {ansi.style(msg,msg_style)}") lines.append(f" {ansi.style(msg,msg_style)}")
if args.divider: if args.divider:
lines.append(divider(len("$(HELP_SEP)") + sum(maxlens) + 2)) lines.append(
ansi.style(
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
"$(DIVIDER_STYLE)",
)
)
if args.whitespace: if args.whitespace:
lines.append("\n") lines.append("\n")
@ -131,7 +89,7 @@ def fmt_rawmsg(msg, argstr, maxlens):
def print_help(): def print_help():
lines = [f"""$(USAGE)"""] lines = [f"""$(USAGE)"""]
items = list(parse_help(gen_makefile())) items = list(parse_make(gen_makefile()))
maxlens = MaxLens( maxlens = MaxLens(
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"]) *(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
) )
@ -148,21 +106,5 @@ def print_help():
print("\n".join(lines)) print("\n".join(lines))
def print_arg_help(help_args):
for arg in help_args.split():
print(f"{ansi.style('task.mk recipe help','$(HEADER_STYLE)')}\n")
print("\n".join(parse_goal(gen_makefile(), arg)))
def main():
help_args = os.getenv("HELP_ARGS")
if help_args:
quit_make()
print_arg_help(help_args)
else:
print_help() print_help()
if __name__ == "__main__":
main()
#% endblock %# #% endblock %#

View file

@ -1,12 +0,0 @@
#% extends "py-script.mk" %#
#% block name %#quit_make#% endblock %#
#% block script %#
import os, signal
def quit_make():
os.kill(os.getppid(), signal.SIGQUIT)
#% endblock %#

View file

@ -1,24 +1,24 @@
# ---- [python/bash script runner] ---- # # ---- [python/bash script runner] ---- #
###-- modified from https://unix.stackexchange.com/a/223093 -### ###-- modified from https://unix.stackexchange.com/a/223093 -###
define _newline define \n
endef endef
_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
_escape_printf = $(subst \,\\,$(subst %,%%,$1)) escape_printf = $(subst \,\\,$(subst %,%%,$1))
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1))) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
_printline = printf -- "<----------------------------------->\n" printline = printf -- "<----------------------------------->\n"
ifdef DEBUG ifdef DEBUG
define _debug_runner define _debug_runner
@printf "$(1) Script:\n";$(_printline); @printf "$(1) Script:\n";$(printline);
@printf "$(call _create_string,$(3))\n" | cat -n @printf "$(call create_string,$(3))\n" | cat -n
@$(_printline) @$(printline)
@$(2) <(printf "$(call _create_string,$(3))") @printf "$(call create_string,$(3))" | $(2)
endef endef
py = $(call _debug_runner,Python,python3,$($(1))) py = $(call _debug_runner,Python,python3,$($(1)))
tbash = $(call _debug_runner,Bash,bash,$($(1))) tbash = $(call _debug_runner,Bash,bash,$($(1)))
else else
py = @python3 <(printf "$(call _create_string,$($(1)))") py = @python3 <(printf "$(call create_string,$($(1)))")
tbash = @bash <(printf "$(call _create_string,$($(1)))") tbash = @bash <(printf "$(call create_string,$($(1)))")
endif endif
pysh = python3 <(printf "$(call _create_string,$($(1)))") pysh = python3 <(printf "$(call create_string,$($(1)))")

114
task.mk
View file

@ -1,7 +1,7 @@
# }> [github.com/daylinmorgan/task.mk] <{ # # }> [github.com/daylinmorgan/task.mk] <{ #
# Copyright (c) 2022 Daylin Morgan # Copyright (c) 2022 Daylin Morgan
# MIT License # MIT License
# version: v22.9.19-5-g5f593e3-dev # version: 22.9.19
# #
# task.mk should be included at the bottom of your Makefile with `-include .task.mk` # 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. # See below for the standard configuration options that should be set prior to including this file.
@ -18,12 +18,7 @@ HELP_SEP ?= │
# python f-string literals # python f-string literals
EPILOG ?= EPILOG ?=
USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n USAGE ?={ansi.$(HEADER_STYLE)}usage{ansi.end}:\n make <recipe>\n
INHERIT_SHELL ?= # ---- [buitlin recipes] ---- #
# ---- [builtin recipes] ---- #
ifeq (help,$(firstword $(MAKECMDGOALS)))
HELP_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
export HELP_ARGS
endif
## h, help | show this help ## h, help | show this help
.PHONY: help h .PHONY: help h
help h: help h:
@ -52,32 +47,29 @@ _update-task.mk:
$(call tprint,{a.b_cyan}Updating task.mk{a.end}) $(call tprint,{a.b_cyan}Updating task.mk{a.end})
curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk curl https://raw.githubusercontent.com/daylinmorgan/task.mk/main/task.mk -o .task.mk
export MAKEFILE_LIST export MAKEFILE_LIST
ifndef INHERIT_SHELL
SHELL := /bin/bash
endif
# ---- [python/bash script runner] ---- # # ---- [python/bash script runner] ---- #
define _newline define \n
endef endef
_escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1)))) escape_shellstring = $(subst `,\`,$(subst ",\",$(subst $$,\$$,$(subst \,\\,$1))))
_escape_printf = $(subst \,\\,$(subst %,%%,$1)) escape_printf = $(subst \,\\,$(subst %,%%,$1))
_create_string = $(subst $(_newline),\n,$(call _escape_shellstring,$(call _escape_printf,$1))) create_string = $(subst $(\n),\n,$(call escape_shellstring,$(call escape_printf,$1)))
_printline = printf -- "<----------------------------------->\n" printline = printf -- "<----------------------------------->\n"
ifdef DEBUG ifdef DEBUG
define _debug_runner define _debug_runner
@printf "$(1) Script:\n";$(_printline); @printf "$(1) Script:\n";$(printline);
@printf "$(call _create_string,$(3))\n" | cat -n @printf "$(call create_string,$(3))\n" | cat -n
@$(_printline) @$(printline)
@$(2) <(printf "$(call _create_string,$(3))") @printf "$(call create_string,$(3))" | $(2)
endef endef
py = $(call _debug_runner,Python,python3,$($(1))) py = $(call _debug_runner,Python,python3,$($(1)))
tbash = $(call _debug_runner,Bash,bash,$($(1))) tbash = $(call _debug_runner,Bash,bash,$($(1)))
else else
py = @python3 <(printf "$(call _create_string,$($(1)))") py = @python3 <(printf "$(call create_string,$($(1)))")
tbash = @bash <(printf "$(call _create_string,$($(1)))") tbash = @bash <(printf "$(call create_string,$($(1)))")
endif endif
pysh = python3 <(printf "$(call _create_string,$($(1)))") pysh = python3 <(printf "$(call create_string,$($(1)))")
# ---- [python scripts] ---- # # ---- [python scripts] ---- #
define help_py define help_py
import argparse import argparse
@ -85,12 +77,10 @@ from collections import namedtuple
import os import os
import re import re
$(ansi_py) $(ansi_py)
$(quit_make_py)
MaxLens = namedtuple("MaxLens", "goal msg") MaxLens = namedtuple("MaxLens", "goal msg")
pattern = re.compile( pattern = re.compile(
r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$" r"^## (?P<goal>.*?) \| (?P<msg>.*?)(?:\s?\| args: (?P<msgargs>.*?))?$$|^### (?P<rawmsg>.*?)?(?:\s?\| args: (?P<rawargs>.*?))?$$"
) )
goal_pattern = re.compile(r"""^(?!#|\t)(.*):.*\n\t""", re.MULTILINE)
def parseargs(argstring): def parseargs(argstring):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--align") parser.add_argument("--align")
@ -106,51 +96,16 @@ def gen_makefile():
with open(file, "r") as f: with open(file, "r") as f:
makefile += f.read() + "\n\n" makefile += f.read() + "\n\n"
return makefile return makefile
def parse_help(file, hidden=False): def parse_make(file):
for line in file.splitlines(): for line in file.splitlines():
match = pattern.search(line) match = pattern.search(line)
if match: if match:
if ( if not os.getenv("SHOW_HIDDEN") and str(
not hidden match.groupdict().get("goal")
and not os.getenv("SHOW_HIDDEN") ).startswith("_"):
and str(match.groupdict().get("goal")).startswith("_")
):
pass pass
else: else:
yield {k: v for k, v in match.groupdict().items() if v is not None} yield {k: v for k, v in match.groupdict().items() if v is not None}
def recipe_help_header(goal):
item = [
i
for i in list(parse_help(gen_makefile(), hidden=True))
if "goal" in i and goal == i["goal"]
]
if item:
return fmt_goal(
item[0]["goal"],
item[0]["msg"],
len(item[0]["goal"]),
item[0].get("msgargs", ""),
)
else:
return f" {ansi.style(goal,'$(GOAL_STYLE)')}:"
def parse_goal(file, goal):
goals = goal_pattern.findall(file)
matched_goal = [i for i in goals if goal in i.split()]
output = []
if matched_goal:
output.append(recipe_help_header(matched_goal[0]))
lines = file.splitlines()
loc = [n for n, l in enumerate(lines) if l.startswith(f"{matched_goal[0]}:")][0]
recipe = []
for line in lines[loc + 1 :]:
if not line.startswith("\t"):
break
recipe.append(line)
output.append(divider(max((len(l) for l in recipe)) + 5))
output.append("\n".join(recipe) + "\n")
else:
output.append(f"{ansi.b_red}ERROR{ansi.end} Failed to find goal: {goal}")
return output
def fmt_goal(goal, msg, max_goal_len, argstr): def fmt_goal(goal, msg, max_goal_len, argstr):
args = parseargs(argstr) args = parseargs(argstr)
goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)" goal_style = args.goal_style.strip() if args.goal_style else "$(GOAL_STYLE)"
@ -160,8 +115,6 @@ def fmt_goal(goal, msg, max_goal_len, argstr):
+ f" $(HELP_SEP) " + f" $(HELP_SEP) "
+ ansi.style(msg, msg_style) + ansi.style(msg, msg_style)
) )
def divider(len):
return ansi.style(f" {'$(DIVIDER)'*len}", "$(DIVIDER_STYLE)")
def fmt_rawmsg(msg, argstr, maxlens): def fmt_rawmsg(msg, argstr, maxlens):
args = parseargs(argstr) args = parseargs(argstr)
lines = [] lines = []
@ -178,13 +131,18 @@ def fmt_rawmsg(msg, argstr, maxlens):
else: else:
lines.append(f" {ansi.style(msg,msg_style)}") lines.append(f" {ansi.style(msg,msg_style)}")
if args.divider: if args.divider:
lines.append(divider(len("$(HELP_SEP)") + sum(maxlens) + 2)) lines.append(
ansi.style(
f" {'$(DIVIDER)'*(len('$(HELP_SEP)')+sum(maxlens)+2)}",
"$(DIVIDER_STYLE)",
)
)
if args.whitespace: if args.whitespace:
lines.append("\n") lines.append("\n")
return lines return lines
def print_help(): def print_help():
lines = [f"""$(USAGE)"""] lines = [f"""$(USAGE)"""]
items = list(parse_help(gen_makefile())) items = list(parse_make(gen_makefile()))
maxlens = MaxLens( maxlens = MaxLens(
*(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"]) *(max((len(item[x]) for item in items if x in item)) for x in ["goal", "msg"])
) )
@ -199,19 +157,7 @@ def print_help():
lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens)) lines.extend(fmt_rawmsg(item["rawmsg"], item.get("rawargs", ""), maxlens))
lines.append(f"""$(EPILOG)""") lines.append(f"""$(EPILOG)""")
print("\n".join(lines)) print("\n".join(lines))
def print_arg_help(help_args):
for arg in help_args.split():
print(f"{ansi.style('task.mk recipe help','$(HEADER_STYLE)')}\n")
print("\n".join(parse_goal(gen_makefile(), arg)))
def main():
help_args = os.getenv("HELP_ARGS")
if help_args:
quit_make()
print_arg_help(help_args)
else:
print_help() print_help()
if __name__ == "__main__":
main()
endef endef
define ansi_py define ansi_py
import os import os
@ -309,7 +255,6 @@ endef
define confirm_py define confirm_py
import sys import sys
$(ansi_py) $(ansi_py)
$(quit_make_py)
def confirm(): def confirm():
""" """
Ask user to enter Y or N (case-insensitive). Ask user to enter Y or N (case-insensitive).
@ -321,12 +266,7 @@ def confirm():
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower() answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
return answer == "y" return answer == "y"
if confirm(): if confirm():
sys.exit() sys.exit(0)
else: else:
quit_make() sys.exit(1)
endef
define quit_make_py
import os, signal
def quit_make():
os.kill(os.getppid(), signal.SIGQUIT)
endef endef