1 27e51a95 2022-01-23 op #!/usr/bin/env perl
3 10382cde 2022-01-23 op # Copyright (c) 2022 Omar Polo <op@omarpolo.com>
5 10382cde 2022-01-23 op # Permission to use, copy, modify, and distribute this software for any
6 10382cde 2022-01-23 op # purpose with or without fee is hereby granted, provided that the above
7 10382cde 2022-01-23 op # copyright notice and this permission notice appear in all copies.
9 10382cde 2022-01-23 op # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 10382cde 2022-01-23 op # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 10382cde 2022-01-23 op # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 10382cde 2022-01-23 op # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 10382cde 2022-01-23 op # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 10382cde 2022-01-23 op # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 10382cde 2022-01-23 op # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 10382cde 2022-01-23 op # subst -- filter that replaces key=values pairs
19 10382cde 2022-01-23 op # usage: subst key1=val1 [... keyn=valn] [files...]
21 10382cde 2022-01-23 op # Use `--' before the first file if it may contain an = in its name.
22 10382cde 2022-01-23 op # If no files are given, read and substitute from standard input.
28 27e51a95 2022-01-23 op my @args = ();
34 27e51a95 2022-01-23 op if ($_ eq '--') {
36 27e51a95 2022-01-23 op } elsif ($_ !~ m/=/) {
37 27e51a95 2022-01-23 op unshift @ARGV, $_;
41 27e51a95 2022-01-23 op my ($match, $repl) = m/^([^\s]*)=(.*)$/;
42 bc451a96 2022-02-10 op push @args, "-e", "s!$match!$repl!g";
45 27e51a95 2022-01-23 op # OK, shelling out to sed is a bit lame...
46 27e51a95 2022-01-23 op exec "sed", @args, @ARGV;