GithubHelp home page GithubHelp logo

shtpl's Introduction

shtpl - a shell template engine

syntax:
#% shell-command
#%# comment
#%include file
#%raw 
#%end raw
#%incraw file (include raw file)
#slurp        (removes trailing newline)
%$            (masks $)    

options:
-ass/--allow-subshell: does not mask $(, ´
-o  /--optimize      : minimize printf usage

usage: sh -c "$( shtpl [options] template )"

Should work with busybox ash, dash, bash, ksh and zsh.
 
(License: GPLv3+)

Installation:

sudo make install

Example Templates:

$ cat testfile
  #%include testfile2
  
  
  #%incraw testraw
   
  #% for i in first "second\"" third; do 
  #% str=super; [ "$i" = "third" ] && str="not so super" 
     blubber test $i ist $str, #slurp
     keine'\\" frage
  #% done 
    blub!
  
  #%raw
  #%echo Hello
  #%end raw

  #%#include testfile2

$ cat testfile2
  #% date="$( date )"
     $date
     $( date )
     ` date `
     ./*.sh 
     <( ls )
     %$date
 
 $ cat testraw 
 Blubber blubb
 blub
 blubber blub
 $date
 $
 #% echo blub
 ` date `
 $(

shtpl's output:

$ shtpl testfile
date="$( date )"
printf "%s\n" "   $date"
printf "%s\n" "   \$( date )"
printf "%s\n" "   \` date \`"
printf "%s\n" "   ./*.sh "
printf "%s\n" "   <( ls )"
printf "%s\n" "   \$date"
printf "%s\n" ""
printf "%s\n" ""
printf "%s\n" "Blubber blubb"
printf "%s\n" "blub"
printf "%s\n" "blubber blub"
printf "%s\n" "\$date"
printf "%s\n" "\$"
printf "%s\n" "#% echo blub"
printf "%s\n" "\` date \`"
printf "%s\n" "\$("
printf "%s\n" ""
printf "%s\n" ""
 for i in first "second\"" third; do 
 str=super; [ "$i" = "third" ] && str="not so super" 
printf "%s" "   blubber test $i ist $str, "
printf "%s\n" "   keine'\\\\\" frage"
 done 
printf "%s\n" "  blub!"
printf "%s\n" ""
printf "%s\n" "#%echo Hello"
printf "%s\n" ""
#include testfile2

Results in:

$ sh -c "$( shtpl testfile )"
  Sam Jun  2 22:59:29 CEST 2012
  $( date )
  ` date `
  ./*.sh
  <( ls )
  $date


Blubber blubb
blub
blubber blub
$date
$
#% echo blub
` date `
$(


   blubber test first ist super,    keine'\\" frage
   blubber test second" ist super,    keine'\\" frage
   blubber test third ist not so super,    keine'\\" frage
  blub!
 
#%echo Hello

shtpl's People

Contributors

dontsueme avatar

Stargazers

 avatar

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.