dotfiles/local/bin/zzexe

33 lines
617 B
Bash
Executable File

#!/bin/sh
if [ "$1" == "-d" ]; then
shift
tail -n +11 "$@" | zstd -do "$@"~ &&
mv "$@"~ "$@"
chmod +x "$@"
else
if [ "$1" == "-p" ]; then
shift
prefix="$1 "
shift
fi
cat > "$@"~ << 'EOF'
#!/bin/sh
dir=`dirname $0`
out=`mktemp -t .zzXXXX`
tail -n +11 $0 | zstd -cd > $out
chmod +x $out
ln -s $out $dir
trap "res=$?" 0 1 2 3 5 10 13 15
EOF
echo $prefix'$dir/`basename $out` $@' >> "$@"~
cat >> "$@"~ << 'EOF'
rm $out $dir/`basename $out`
exit $res
EOF
zstd --ultra -22 "$@"
rm "$@"
cat "$@"~ "$@".zst > "$@"
rm "$@".zst "$@~"
chmod +x "$@"
fi