#!/bin/sh
# Runs a stream command on a file
# Usage: self file command
file="$1"
shift
temp="$(tempfile)"
trap "rm -f $temp" EXIT
"$@" <"$file" >"$temp" || exit
diff "$file" "$temp" >/dev/null && exit # don't update file if no change
mv "$temp" "$file"