Giter VIP home page Giter VIP logo

shpp's Introduction

Simple Shell Preprocessor

Executes all text inside '%{' '}%' delimiters in the source text with a given program (default: /bin/sh) and inserts the stdout and stderr back into the original text.

More specifically, the text blocks will be given to the program as a positional argument and executed as

<prog> -c <text> [<args> ... ]

Inspired by pp and the rc templating language https://werc.cat-v.org/docs/rc-template-lang.

Installation

go install github.com/wlcsm/shpp@latest

Configuration

  • SHPP_COMMAND The command used to execute the codeblock (default: /bin/sh)

Examples

Basic usage will be to include the templated file as a positional argument

$ cat template.html
<p>%{echo "Hello, world}%</p>

$ shpp template.html
<p>Hello, world</p>

shpp will read from stdin if no arguments are supplied.

$ shpp < template.html
<p>Hello, world</p>

When the code inside the delimiters is executed, it will have access to STDIN, environment variables, and positional arguments of the parent process.

Passing via stdin

$ cat template.html
<p>%{ cat }%</p>

$ echo 'Hello World' | shpp template.yaml
<p>Hello, world</p>

Passing via environment variables

$ echo '%{echo $MSG}%' | MSG='Hello, world' ./shpp
Hello, world

Passing via positional arguments

$ cat template.html
<p>%{ echo $1, $2 }%</p>

$ echo 'Hello World' | shpp template.yaml 'Hello' 'world'
<p>Hello, world</p>

The "-" character may be used in place of the source file name to signify the template should be read from STDIN. This is useful when needed to provide positional arguments.

$ echo '%{printf $1 $2}%' | shpp - 'Hello,' 'world'
Hello, world

The program used to execute the code blocks may be configured with the SHPP_COMMAND environment variable

$ echo '%{print("Hi")}%' | SHPP_COMMAND="$(which python3)" ./shpp
Hi

shpp's People

Contributors

wlcsm avatar

Stargazers

Robbie Cronin avatar

Watchers

 avatar

Forkers

aaronjauregui

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.