Text preprocessor for content segmentation.
With go 1.18 or higher:
go install github.com/x0k/mk@latest
mkfile
file
TARGET="mk"
build:
go build -o ./bin/${TARGET}
clean:
go clean
rm -f ./bin/${TARGET}
mk build
output
TARGET="mk"
go build -o ./bin/${TARGET}
mk clean
output
TARGET="mk"
go clean
rm -f ./bin/${TARGET}
If file contains x
suffix, then result of preprocessing will be saved as tmp file and executed.
mkfilex
file
#!/usr/bin/bash
echo "zero"
one:
echo "one"
echo $1
two:
echo "two"
mk one
output
zero
one
mk two my-one
output
zero
my-one
two
Each segment can define its targets.
If the segment has a target that is a prefix of current target segment, it will be included in the result.
mkfilex
file
#!/usr/bin/bash
prepare: test build
echo "prepare"
build:
echo "build"
test:
echo "test"
clean:
echo "clean"
mk build
output
prepare
build
mk clean
output
clean
The equivalent mkfilex
#!/usr/bin/bash
clean:
echo "clean"
echo "prepare"
build:
echo "build"
test:
echo "test"
By default target segment is default
and all segments are implicitly declare default
as their target.
So $ mk
command will include all segments in the result.
If you want to exclude some segment from $ mk
result, then:
- define segment with target (any non-empty string/strings not beginning with
default
) - define segment after
default
segment.
mkfilex
file
#!/usr/bin/bash
build:
echo "build"
test: build
echo "test"
default:
clean:
echo "clean"
mk
output
build
-
The segment defined by a label (and optional targets) that satisfies this regular expression
^([A-z][0-9A-z\._-]*):(.*)$
and by the presence of equal indentation^([ \t]+)
on the subsequent lines.By default segment is not defined.
-
Segment targets are a whitespace-separated list of segment prefixes that follow the
:
character. -
The end of a segment is determined by indentation changes or the end of the file.
-
If segment is not defined for a line, the line will be added to each segment defined below.
-
The filename must match the regular expression
^(M|m)kfile.*$
, all matching files are processed in reverse lexicographic order until the target segment is found.