Created: 2021-09-12 Sun Last modified: 2023-01-12 Thu
mk: Bash-based Automation Tool¶
2023-01-12 Thu
Renamed from
makeittomk
Features¶
Bash as a language
Shared context
Target is defined as a bash function
Targets can depends on others
Multiple targets can be invoked
Autocompletion support
Motivation¶
I've regularly found myself creating bash scripts with names like build, run, clear.
Typically, these scripts should share some variables and I'd had to duplicate them or use other techniques
(like env variables, source common script). I wasn't satisfied with it.
Also, I used Makefile-s. Specifically, I liked the completion feature. But Makefile has its own
features, that were not convenient for me (like specific Makefile syntax, separate execution of every line by
default).
For my purposes, I wanted to have a single file that contains bash scenarios with the ability to share common variables and functions, and with autocomplete feature in order to launch them easily.
Demo¶
Getting Started¶
Enable autocompletion
$ wget https://raw.githubusercontent.com/ilya-bystrov/mk/master/completions/mk_completions -O - >> ~/.bash_completion
$ wget https://raw.githubusercontent.com/ilya-bystrov/mk/master/completions/mk_alias -O - >> ~/.bash_completion
Use template
$ wget https://raw.githubusercontent.com/ilya-bystrov/mk/master/mk
$ chmod u+x mk
$ mk <Tab>
bye hello
$ mk hello
Hello, World!
$ mk bye
bye-bye.
Customize
mkfor your own needs
Concept¶
The key idea is iterating through arguments that corresponds to function names and invoking this functions
Use the template
By default
/usr/bin/env bashshebangerrexit,pipefail,nounsetbash options
Or build your own
Example¶
docker-container-management¶
Requires docker installed
$ cd mk/examples/docker-container-management/mk
$ mk build # build 'someimage' docker image based on 'busybox'
$ mk run # run 'someimage' image inside 'somecontainer' container
$ mk rm # remove 'somecontainer' container
$ mk rmi # remove 'someimage' image
Improvements¶
Feel free to suggest improvements