miscutils/ts

53 lines
596 B
Plaintext
Raw Normal View History

#!/bin/ksh
function tsrun
{
typeset err out ret
err=$(mktemp /tmp/XXXXXXXXXX)
out=$(mktemp /tmp/XXXXXXXXXX)
trap "rm $err $out" EXIT
eval "$@" >$out 2>$err
ret=$?
sed 's/^/| /' $out
sed 's/^/@ /' $err
print '? '$ret
}
function tseval
{
typeset ln
while read ln
do
case ${ln%% *} in
$)
print "$ln"
tsrun "${ln#$}"
;;
!(?|@|\|))
print "$ln"
;;
esac
done
}
(( $# == 0 )) && exit 64
if [[ $1 = -b ]]
then
(( $# == 1 )) && exit 64
shift
for fn
do
cp $fn $fn~
(rm $fn && tseval >$fn) <$fn
done
else
for fn
do
tseval <$fn | diff -u $fn -
done
fi