jirutka / esh

Simple templating engine based on shell.
MIT License
214 stars 16 forks source link

Utility Imports #15

Open E8y2FqZE opened 5 months ago

E8y2FqZE commented 5 months ago

Is there a good way to import my own utilities globally without manually importing them from every file?

For example, if I have this:

# util.sh

hash_file() {
    md5sum $1 | cut -f1 -d ' ' | tr -d '\n'
}

I can then write a template that imports my utility like this:

# my_template.conf.esh
<% . util.sh -%>

foo=123
bar=<% hash_file big_data.dat %>

I'm imagining a flag for esh that allows this on the command line so I don't have to manually import utilities in each of my template files, e.g.: esh -i utils/net.sh -i utils/data.sh -o output.conf input.conf.esh. My gut is telling me there's some kind of way to do this in the shell by altering the environment or passing some flags to the shell interpreter (-s flag) without altering esh, but I can't figure it out.