1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2024-11-08 16:04:37 +00:00
dotfiles/bin/zzexe

33 lines
631 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
cat > "$1"~ << '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` $@' >> "$1"~
cat >> "$1"~ << 'EOF'
rm "$out" "$dir"/`basename $out`
exit $res
EOF
zstd --ultra -22 "$1"
rm "$1"
cat "$1"~ "$1".zst > "$1"
rm "$1".zst "$1~"
chmod +x "$1"
fi