2024-03-29 13:01:40 +01:00

2.2 KiB

Bash Script Compiler 0.1

A helper / compiler to maintain bigger bash script projects where you develop in multiple files, one file per function, so everything should be better maintainable.

You can create new stub projects with this so you do not need to take care about the boilerplate code, just implement your neccessary functions, help, code completion.

On executing this script merges everything together into a file in a dist folder in the project.

Getting started

Execute

bash-script-compiler new

and answer the questions to create a new bash script project.

Main idea

TODO explain the directory structure src/ src/functions scr/help src/intro.sh src/main.sh src/xyz-completion LICENSE README.md VERSION

Split

  1. Put the main part of your project into the ./src/main.sh file. It will be the entrypoint for your script;
  2. Move all your function declarations into the modules under the ./lib directory (./lib/print_bar.sh and ./lib/print_foo.sh in this example);
  3. Copy the content of the Makefile to the root of your project;

Build

  1. Replace the value of the variable TARGET_FILE in the Makefile (wich is target.sh by default) with the name that your prefer;
  2. Run make from your project directory;
  3. The content of your main.sh file will be wrapped into the main function and will be invoked at the end of the script, so all of the functions defined in modules under the lib directory will be available in it;

Changelog

0.3

  • Added support for variable replacement
  • Small code refactorings
  • Added a VARIABLES file that is read for the variables
  • Added run flag to the compiled script
  • Updated the init files

0.2

  • Added support for deploying (copying) to a (configurable) path
  • Added configuration

0.1

  • Created the initial script
  • Split it up so it will compile itself (this therefor serves as example project)

Open issues

  • Implement creating a new bash script project

Sources