I will be removing macOS binaries on Sun Dec 5 2021 because they're not signed. If you prefer having macOS binaries, please consider donating for an Apple Developer Program subscription which is 100$. Also, 70$ per month for an Apple Silicon server. Send an email to adi@tilde.institute!

Docs

pp

a preprocessor

pp allows embedding sh code in files of any type by nesting it inside the #!\n token, where \n is a new line. That means that if you'd like a simple loop or an if inside an HTML file for instance, you could use pp.

Usage

For the following code:

<!doctype html>
<title>pp example</title>
<ul>
#!
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
#!
	<li class=even>$i</li>
#!
else
#!
	<li class=odd>$i</li>
#!
fi
i=$((i + 1))
done
#!
</ul>

pp outputs:

<!doctype html>
<title>pp example</title>
<ul>
        <li class=odd>1</li>
        <li class=even>2</li>
        <li class=odd>3</li>
        <li class=even>4</li>
        <li class=odd>5</li>
        <li class=even>6</li>
        <li class=odd>7</li>
        <li class=even>8</li>
        <li class=odd>9</li>
        <li class=even>10</li>
</ul>

Arguments

You can also pass arguments to it by appending them to the command call:

<!doctype html>
<title>$1</title>
<p>
#!
	echo $2
#!
</p>

Calling the above code with pp tmp.upphtml 'pp example' 'hello, world' will result in:

<!doctype html>
<title>pp example</title>
<p>
hello world
</p>

Pipes

pp's stdin is sent to the child sh

<!doctype html>
<title>pp example</title>
<p>
#!
	cat
#!
</p>

echo 'hello, world' | pp tmp.upphtml will output:

<!doctype html>
<title>pp example</title>
<p>
hello, world
</p>

Debugging

pp also takes an optional -d flag. If passed, pp will dump the generated sh code instead of executing it:

<!doctype html>
<title>pp example</title>
<ul>
#!
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
#!
	<li class=even>$i</li>
#!
else
#!
	<li class=odd>$i</li>
#!
fi
i=$((i + 1))
done
#!
</ul>

pp -d tmp.upphtml will output:

echo "<!doctype html>
<title>pp example</title>
<ul>"
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
echo "  <li class=even>$i</li>"
else
echo "  <li class=odd>$i</li>"
fi
i=$((i + 1))
done
echo "</ul>"

Example

<!doctype html>
<html lang=en>
<title>pp</title>
<meta charset=UTF-8>
<meta name=viewport content='width=device-width, initial-scale=1'>
<link rel=stylesheet href=../theme.css>
<body>
<a href=../#myprojects>Home</a>
#!
addcls() {
	sed "s/<code>/<code class=language-bash>/g"
}
smu README | addcls
#!
<h2>Files</h2>
<ul>
#!
for f in *
do
case $f in
	*.upp*|*.html|*.tgz)
	continue
	;;
esac
#!
<li><a href=$f>$f</a></li>
#!
done
#!
</ul>
<h2>Download</h2>
<a href=pp.tgz>pp.tgz</a>
<script src=../prism.js data-manual></script>
<script src=../enhance.js></script>
</body>
</html>

See also

Files

Sources

pp@1.0.11.tgz

🗣️ Please share

Facebook Twitter Pinterest LinkedIn WhatsApp Telegram Email

🌟Built with mkws

  1. vltra.plus
    https://vltra.plus
  2. dont-be-evil.com
    https://dont-be-evil.com
  3. peguero.xyz
    https://peguero.xyz
  4. nfld.uk
    https://nfld.uk
  5. andrewjvpowell.com
    https://andrewjvpowell.com
  6. adi.onl
    https://adi.onl
  7. mkws.sh
    https://mkws.sh

🗨️What people are saying

🏅Sponsors

  1. Steven Peguero
  2. Josemar Muller Lohn
  3. James Mills
  4. John Jarvis
  5. Andrew Powell

🎁How to contribute

Make a web site 😉 and send a link to adi@tilde.institute!

You can also sponsor me:

🗣️ Please share

Facebook Twitter Pinterest LinkedIn WhatsApp Telegram Email