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