1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2024-12-25 06:36:42 +00:00
dotfiles/bin/zzexe

34 lines
669 B
Bash
Executable file

#!/bin/sh
if [ "$1" = "-d" ]; then
shift
tail -n +11 "$1" | zstd -do "$1"~ &&
mv "$1"~ "$1"
chmod +x "$1"
else
if [ "$1" = "-p" ]; then
shift
prefix="$1 "
shift
fi
echo '#!/bin/sh' > "$1"~
echo out=\`mktemp -t .zzXXXX."${1##*.}"\` >> "$1"~
cat >> "$1"~ << 'EOF'
dir=`dirname "$0"`
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` $@' >> "$1"~
cat >> "$1"~ << 'EOF'
rm "$out" "$dir"/`basename $out`
exit $res
EOF
zstd --ultra -22 "$1" &&
cat "$1"~ "$1".zst > "$1"
rm "$1".zst "$1~"
chmod +x "$1"
fi