stargazing/notwa-util/shed

13 lines
357 B
Text
Raw Normal View History

#!/usr/bin/env sh
: \
&& f="${1?missing filename}" && shift \
2022-10-01 18:26:12 -07:00
&& for e in "$@" \
;do : \
2022-10-01 18:26:12 -07:00
&& { cp "$f" "$f.bak" || exit ;} \
&& sed -i -e "$e" "$f" \
&& { diff -q "$f" "$f.bak" >/dev/null; x=$?; rm "$f.bak" || exit ;} \
&& [ $x = 1 ] \
|| { printf >&2 '\033[91mfailed to apply sed:\033[m\n%s\n' "$e"; exit 1 ;} \
;done \
;