Skip to content
The friendly pre-processor
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

  ___  _ _  ___ | |
 | p \| r_>/ e_>!_/
 |  _/|_|  \___.<_>

PRE! The friendly pre-processor.

MIT License. Leon Bambrick 2014


pre $file        

...process a file, replacing "codeblocks" with their result. write the result to the same file, with .pre suffix removed from the name. e.g. pre 'person.cs.pre' will write to 'person.cs' while pre 'person.cs' will overwrite 'person.cs' (as there is no .pre suffix to be replaced)

pre_help on pre


...verbose help on pre, with details about codeblocks.

               _       _    _            _       
   ___  ___  _| | ___ | |_ | | ___  ___ | |__ ___
  / | '/ . \/ . |/ ._>| . \| |/ . \/ | '| / /<_-<

A codeblock is a {language:expression:} embedded in a file that pre replaces with the result of its invocation. Currently there are three kinds of codeblocks that can be used: powershell, sql and NimbleText patterns.

powershell codeblocks look like this:

dir c:\

SQL codeblocks look like this, and are executed against the connection from $env:conn

select * from sysobjects

NimbleText codeblocks look like this, and are mixed with the data from file named $env:ntdata

Hello $0 how are you.

When pre is run, the codeblocks are replaced with the result of their execution. The start and end tags of a code block must be on their own line. So you can't do this:

{sql:select * from sysobjects:} ← this won't work. yet

The start and end tags can be wrapped in whatever is the native multi-line comment for the platform, e.g.

 /* {powershell:
 dir c:\
 :} */

...this works because the start tag only has to be the last thing on the line, and the end tag only has to be the first thing on the line. Any other text on tag start/end lines is assumed to be comments, and is discarded/replaced.

Why? Why!?

You can make living documents. Perhaps you're writing a book in markdown and you want sections to be self updating.

Perhaps you want a light sprinkling of code generation inside your projects.

Getting started...

Dot source the file pre.ps1. i.e, run this:

. .\pre.ps1

...perhaps as part of your $PROFILE.

Thereafter you will have the 3 functions available:

  • pre
  • pre_help
  • pre_help_detailed
You can’t perform that action at this time.