12 lines
357 B
Bash
Executable file
12 lines
357 B
Bash
Executable file
#!/usr/bin/env sh
|
|
: \
|
|
&& f="${1?missing filename}" && shift \
|
|
&& for e in "$@" \
|
|
;do : \
|
|
&& { 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 \
|
|
;
|