Skip to content

jirutka/esh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Packaging status

Alpine Linux

Install package esh from the Alpine’s community repository:

apk add esh

Fedora

dnf install esh

Void Linux

xbps-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.2/esh \
    && echo '9084e3e8e70e4ea81c40cd1cf85559196c0fa2cc  esh' | sha1sum -c \
    || exit 1

Manually

  1. Download and unpack release tarball:

    wget https://github.com/jirutka/esh/archive/v0.3.2/esh-0.3.2.tar.gz
    tar -xzf esh-0.3.2.tar.gz
    cd esh-0.3.2
  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.