edit.sh in git
EDIT(1)                 FreeBSD General Commands Manual                EDIT(1)

NAME
     edit – interactive script

SYNOPSIS
     edit [replacement]

DESCRIPTION
     edit creates a temporary sh(1) script from standard input and invokes
     EDITOR before it executes.  The replacement argument is used in a sed(1)
     substitute expression to generate the script.  The default replacement is
     ‘: &’.

EXAMPLES
           ls | edit 'mv & &'

FreeBSD 12.0-RELEASE-p10        August 29, 2019       FreeBSD 12.0-RELEASE-p10
#!/bin/sh
set -eu

script=$(mktemp)
trap "rm -f '$script'" EXIT

sed "s/.*/${1:-: &}/" >> "$script"
$EDITOR "$script"
sh -eux "$script"