Last active
January 19, 2025 12:03
-
-
Save fuzzy/2375e82c3fdbe2187edde5eee6d299f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
comp=${COMPRESSOR:-$(which gzip 2>/dev/null)} | |
flags="" | |
case "${1}" in | |
(compress) shift ;; | |
(decompress) op="d"; flags="-d"; shift ;; | |
(*) echo "Usage: ${0} (compress|decompress) [-vjJzZc] <...>" ; exit 1 ;; | |
esac | |
while getopts "vjJzZc" opt; do | |
case "${opt}" in | |
(v) flags="${flags} -v" ;; | |
(j) comp=$(which bzip2 2>/dev/null) ;; | |
(J) comp=$(which xz 2>/dev/null) ;; | |
(z) comp=$(which gzip 2>/dev/null) ;; | |
(c) comp="$(which compress 2>/dev/null) -f" ;; | |
(Z) comp="$(which zstd 2>/dev/null) --no-progress --rm" ;; | |
(*) | |
echo "Usage: ${0} compress [-vjJzZc] <...>" | |
printf "\t-v verbose\t-j use bzip2\n\t-J use xz" | |
printf "\t-z use gzip (Def)\n\t-Z use zstdio\t-c use compress\n" | |
exit 1 ;; | |
esac | |
done | |
for archive in ${@}; do | |
if test ! -z "${op}"; then | |
mtype=$(file ${archive}|head -n1|awk '{print $2}') | |
case "${mtype}" in | |
(XZ) comp=$(which xz 2>/dev/null) ;; | |
(Zstandard) comp="$(which zstd 2>/dev/null) --no-progress -f --rm" ;; | |
(compress\'d) comp="$(which compress 2>/dev/null) -f" ;; | |
(*) comp=$(which ${mtype} 2>/dev/null) ;; | |
esac | |
fi | |
test -e "${archive}" || continue && \ | |
${comp:-$(which gzip 2>/dev/null)} ${flags} ${archive} >/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment