On 21-05-2011 19:34:34 +0200, Jeroen Roovers wrote:
> On Fri, 20 May 2011 17:56:00 +0200
> Fabian Groffen <[email protected]> wrote:
>
> > sed -e "<pattern>" "${file}" | diff "${file}" -
> >
> > followed by the actual sed -i -e ...
> >
> > This way I didn't need to write an intermediate file.
>
> The problem there is that sed might be called just once on any one file,
> but in the tree it is often invoked with multiple scripts, so this
> simple implementation lacks a way to evaluate which sed scripts are
> useful.
>
> Also, how do I ensure the sed replacement works only on invocations
> inside the ebuild, and not, say, in portage's internals?
(not tested, but as proof of concept)
alias sed my_sed
my_sed() {
local oargs="${@}"
local arg
local nargs=()
local hadi=
local hade=
while [[ -n $1 ]] ; do
case "$1" in
-i)
# ignore this flag
hadi=yes
;;
-e|-f)
shift
nargs+=( "-e$1" )
hade=yes
;;
-*)
nargs+=( "$1" )
hade=yes
;;
*)
if [[ -z ${hade} ]] ; then
nargs+=( "$1" )
elif [[ -z ${hadi} ]] ; then
# there is no inline replacing, not
much we can do
break
else
sed "${nargs[@]}" "$1" | diff -q "$1" -
> /dev/null \
&& ewarn "sed ${oargs} has no
effect on $1"
fi
;;
esac
shift
done
\sed "${oargs}"
}
--
Fabian Groffen
Gentoo on a different level