Norcoen / esh

Simple templating engine based on shell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ESH – Embedded SHell

Build Status

esh (embedded shell) is a templating engine for evaluating shell commands embedded in arbitrary templates. It’s like ERB (Embedded RuBy) for shell, intended to be used for templating configuration files. Unlike ERB it provides support for including one ESH template into another (since version 0.2.0).

The template processing consists of two phases: conversion to a shell script and evaluation of that script. You can even run just the conversion phase: esh -d will dump a shell script that you can execute directly by a shell (even on a system without esh installed). However, in that case, you will not get error messages source-mapped to point to the locations in the template file.

esh is implemented in ~290 lines (LoC) of shell and awk.

Requirements

  • POSIX-sh compatible shell (e.g. Busybox ash, dash, ZSH, bash, …)

  • common Unix userland with awk and sed (e.g. from Busybox, GNU, …)

  • (Asciidoctor to build a man page)

Installation

Alpine Linux

Install package esh from the Alpine’s community repository:

apk add esh
Important
This package is in Alpine stable since v3.7. You can also install it from edge (unstable) branch.

Fedora

dnf install esh

openSUSE

Install package esh from my repository on openSUSE Build Service:

zypper addrepo http://download.opensuse.org/repositories/home:jirutka/openSUSE_Leap_15.0/home:jirutka.repo
zypper refresh
zypper install esh

On CI

You can add esh as a submodule into your repository or download it on demand, e.g.:

wget https://raw.githubusercontent.com/jirutka/esh/v0.3.0/esh \
    && echo 'fe030e23fc1383780d08128eecf322257cec743b  esh' | sha1sum -c \
    || exit 1

Manually

  1. Download and unpack release tarball:

    wget https://github.com/jirutka/esh/archive/v0.3.0/esh-0.3.0.tar.gz
    tar -xzf esh-0.3.0.tar.gz
    cd esh-0.3.0
  2. Run tests:

    make test
  3. Build a man page and install esh:

    make install prefix=/usr/local DESTDIR=/

    or just copy esh whether you want, it’s a plain shell script.

Usage

Read man page esh(1).

Examples

http {
    access_log <%= $logs_dir/access.log %> main;

    resolver <%= $(sed -En 's/^nameserver ([^#]+)/\1/p' /etc/resolv.conf) %>;

    <% if nginx -V 2>&1 | grep -q lua-nginx-module; then -%>
    lua_package_path '<%= $(pkg-config --variable=INSTALL_LMOD lua) %>/?.lua';
    <% fi -%>

    <%+ ./http-common.esh %>

    <%# The rest of the config is omitted %>
}

Credits

ESH template syntax is based on ERB (Embedded Ruby).

Tests and some concepts are inspired by shellcat.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.

About

Simple templating engine based on shell.

License:MIT License


Languages

Language:Shell 84.4%Language:Makefile 15.6%