task.mk/README.md

74 lines
2.6 KiB
Markdown
Raw Normal View History

2022-09-05 18:12:51 -05:00
<div align="center">
<h1 align="center"> task.mk </h1>
<img src="./assets/help.svg" alt="help" width=400 >
<p align="center">
the task runner for GNU Make you've been missing
</p>
2022-09-19 00:20:59 -05:00
<p align="center">
<a href="https://gh.dayl.in/task.mk">Documentation</a>
</p>
2022-09-05 18:12:51 -05:00
</div>
2022-09-19 00:20:59 -05:00
2022-09-05 18:12:51 -05:00
</br>
2022-09-05 13:03:53 -05:00
2022-09-05 18:12:51 -05:00
GNU make is an excellent build tool and the task runner we love to hate, but can't escape.
So let's improve the UX to make it the best task runner it can be.
2022-09-05 13:03:53 -05:00
2022-09-05 18:12:51 -05:00
`Task.mk`, is a standalone `Makefile` you can deploy alongside your own
to add some QOL improvements for your users and fellow maintainers.
2022-09-05 13:03:53 -05:00
Current Features:
2022-09-05 18:12:51 -05:00
- ANSI escape code support (including NO_COLOR)
- formatted help output
- custom print function
2022-09-14 16:52:49 -05:00
- confirmation prompt
2022-09-05 13:03:53 -05:00
Depends on `GNU Make`, obviously and `Python >=3.7`, and `bash` (or `zsh`).
2022-09-05 13:03:53 -05:00
2022-09-05 18:12:51 -05:00
Wait python?!?!, I'm not `pip` installing some package just to parse my makefile.
2022-09-14 13:49:25 -05:00
I agree, all you need is one file [`.task.mk`](./task.mk).
You can automagically include it with just two additional lines to your `Makefile` (and probably one to your `.gitignore`) and your good to go.
2022-09-05 13:03:53 -05:00
2022-09-05 18:12:51 -05:00
## Setup
2022-09-05 13:03:53 -05:00
2023-01-20 13:29:42 -06:00
One line setup:
```bash
bash <(curl -fsSL gh.dayl.in/task.mk/init) # or w/ TASKMK_VERSION=
```
2022-09-05 18:12:51 -05:00
You can include this as an optional dependency on your project by adding the below lines to the end of your `Makefile`.
If someone tries to invoke `make help` it will download `.task.mk` for them.
2022-09-05 13:03:53 -05:00
```make
-include .task.mk
2023-01-20 12:49:38 -06:00
$(if $(filter help,$(MAKECMDGOALS)),$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v23.1.1/task.mk -o .task.mk))
2022-09-05 13:03:53 -05:00
```
2022-09-05 18:12:51 -05:00
2022-09-06 07:49:15 -05:00
You might also consider making it a consistently downloaded dependency if you plan to use any of it's advanced feature set, by dropping the `$(MAKECMDGOALS)` check.
2022-09-05 18:12:51 -05:00
2022-09-06 07:49:15 -05:00
```make
-include .task.mk
2023-01-20 12:49:38 -06:00
$(if $(wildcard .task.mk),,.task.mk: ; curl -fsSL https://raw.githubusercontent.com/daylinmorgan/task.mk/v23.1.1/task.mk -o .task.mk)
2022-09-05 18:12:51 -05:00
```
2022-09-18 10:00:53 -05:00
For more info see the [documentation](https://gh.dayl.in/task.mk).
2022-09-05 18:12:51 -05:00
## Simpler Alternative
But I just want a basic help output, surely I don't need python for this... you would be right.
2022-09-07 00:11:26 -05:00
`Task.mk` replaces my old `make help` recipe boilerplate which may better serve you (so long as you have `sed`/`awk`).
2022-09-05 18:12:51 -05:00
```make
## h, help | show this help
2022-09-19 00:20:59 -05:00
### additional text printed with the help
2022-09-05 18:12:51 -05:00
.PHONY: help h
2022-09-05 20:20:10 -05:00
help h: Makefile
2022-09-05 18:12:51 -05:00
@awk -v fill=$(shell sed -n 's/^## \(.*\) | .*/\1/p' $< | wc -L)\
'match($$0,/^## (.*) \|/,name) && match($$0,/\| (.*)$$/,help)\
{printf "\033[1;93m%*s\033[0m | \033[30m%s\033[0m\n",\
fill,name[1],help[1];} match($$0,/^### (.*)/,str) \
{printf "%*s \033[30m%s\033[0m\n",fill," ",str[1];}' $<
2022-09-05 20:20:10 -05:00
```