The syntax processed by pp
is simple. A line beginning !!
is replaced by the output of the command that follows. For example,
> cat example.txt
The current day is:
!! printf ' >>> '; date '+%Y-%m-%d'
which is in the ISO format.
> pp < example.txt
The current day is:
>>> 2022-04-8
which is in the ISO format.
It is just a simple STDIN->STDOUT program that replaces certain lines with shell output. (Note: As arbitrary shell commands could be run, pp
should only be run on trusted files).
A syntax update would add !{printf '!{
and }!
'}! command brackets that could be picked up as a pair anywhere on one line. For instance,
> cat example2.txt
Todays date is !{date '+%Y-%m-%d'}!, which is my birthday!
> cat example2.txt | pp
Todays date is 2022-04-08, which is my birthday!
This becomes quite powerful using variables that are set at runtime.
> function span_section_blue() {
> printf '<span style="color:blue">%s</span>' "$*"
> }
> cat example3.txt
# Learning about colours
So the relevant word in the next sentence!{#This disappears}! is blue.
Red Green Orange !{ Blue}! Yellow Pink
> cat example3.txt | B=span_section_blue pp
# Learning about colours
So the relevant word in the next sentence is blue.
Red Green Orange <span style="color:blue">Blue</span>' Yellow Pink
But could encounter problems with nested code sections.