Commit Diff


commit - e68057df893e158a49cb96caf50b4cb8c350164e
commit + 27e51a95e57a018328170844079042db2a6eec5e
blob - 32f18427937fbc5afe2b8ec4fe3e792302b00bf6
blob + c804fc56f5631851e80726c73d83333dca9e1c30
--- site/subst
+++ site/subst
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/usr/bin/env perl
 #
 # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
 #
@@ -21,21 +21,26 @@
 # Use `--' before the first file if it may contain an = in its name.
 # If no files are given, read and substitute from standard input.
 
-args=''
+use v5.10;
+use strict;
+use warnings;
 
-for arg; do
-	if [ "$arg" = '--' ]; then
-		break
-	fi
+my @args = ();
 
-	key="$(printf '%s\n' $arg | cut -s -d '=' -f1)"
-	if [ -z "$key" ]; then
-		break
-	fi
-	val="$(printf '%s\n' $arg | cut -d '=' -f 2-)"
-	shift
+while (1) {
+	$_ = shift;
+	last if !$_;
 
-	args="$args -e s/$key/$val/g "
-done
+	if ($_ eq '--') {
+		last;
+	} elsif ($_ !~ m/=/) {
+		unshift @ARGV, $_;
+		last;
+	}
 
-exec sed $args "$@"
+	my ($match, $repl) = m/^([^\s]*)=(.*)$/;
+	push @args, "-e", "s/$match/$repl/g";
+}
+
+# OK, shelling out to sed is a bit lame...
+exec "sed", @args, @ARGV;