appdwarf/zzexe

17 lines
594 B
Plaintext
Raw Normal View History

2022-03-25 22:52:40 +00:00
#!/bin/sh
set -e # exit on failure
IFS=$(printf '\n\t') # smarter ifs
[ "$1" = "-d" ] && awk 'f;/^exit/{f=1}' "$2" | head -c-1 | zstd -cd | ifne sponge "$2" && exit
2022-04-16 23:21:07 +00:00
[ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present
2022-06-12 17:07:52 +00:00
zstdmt -cq19 "$@" | ifne sponge "$1"
echo '#!/bin/sh
2022-04-16 23:21:07 +00:00
dir=$(dirname "$0") out=$(mktemp -t .zzXXXX.
2022-06-12 17:07:52 +00:00
awk "f;/^exit/{f=1}" "$0" | head -c-1 | zstd -cd > "$out"
2022-03-25 22:52:40 +00:00
chmod +x "$out"
ln -s "$out" "$dir"
2022-06-12 17:07:52 +00:00
trap : 0 1 2 3 5 10 13 15
"$dir/$(basename "$out")" "$@"
2022-06-12 17:07:52 +00:00
res=$?
rm "$out" "$dir/$(basename "$out")"
2022-06-12 17:07:52 +00:00
exit $res' | sed "2s/$/${1##*[./]})/;7s/^/$p /" | cat - "$1" | sponge "$1"