-
-
Save nerun/dacb269ac03d13085f7e1465674d4ff1 to your computer and use it in GitHub Desktop.
Universal Compressor (Archiver) and Decompressor (Extractor) for Linux shell.
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
#!/usr/bin/env zsh | |
########################### | |
# ZAP | |
# By Daniel Dias Rodrigues | |
########################### | |
# Se o parâmetro for -c, compactar | |
if [[ $1 == "-c" || $1 == "c" ]]; then | |
local args=("$@") # array de argumentos | |
a=$(echo "$2" | awk '{print tolower($0)}') | |
case $a in | |
# TAR supported formats | |
*.tar.bz2 | *.tbz2 | *.tbz | *.tb2) | |
tar -I pbzip2 -cvf $2 "${args[@]:2}" ;; # Multithreading through pbzip2 | |
*.tar.gz | *.tgz) | |
tar -I pigz -cvf $2 "${args[@]:2}" ;; # Multithreading through pigz | |
*.tar.lz | *.tlz) | |
tar -I plzip -cvf $2 "${args[@]:2}" ;; # Multithreading through plzip | |
*.tar.lzo | *.tzo) | |
tar --lzop -cvf $2 "${args[@]:2}" ;; | |
*.tar.zst | *.tzst) | |
tar -I 'zstd -T0' -cvf $2 "${args[@]:2}" ;; # Multithreading through ZSTD option -T0 | |
*.tar.lzma) | |
tar --lzma -cvf $2 "${args[@]:2}" ;; | |
*.tar) | |
tar -cvf $2 "${args[@]:2}" ;; | |
*.tar.xz | *.txz) | |
tar -I 'xz -vv -T0' -cvf $2 "${args[@]:2}";; # Multithreading through XZ option -T0 | |
*.tar.7z) | |
tar cf - "${args[@]:2}" | 7z a -si $2 ;; # Multithreading by default | |
# OUTROS | |
*.7z) 7z a -r $2 "${args[@]:2}" ;; # Multithreading by default | |
*.arj) arj a -r $2 "${args[@]:2}" ;; | |
*.rar) rar a -r0 $2 "${args[@]:2}" ;; # Multithreading by default | |
*.zip) zip -r $2 "${args[@]:2}" ;; | |
*.zpaq) zpaq a $2 "${args[@]:2}" ;; # Multithreading by default | |
# NÃO SUPORTAM COMPACTAÇÃO DE VÁRIOS ARQUIVOS JUNTOS | |
*.bz2 | *.bz) | |
pbzip2 -kv $2 "${args[@]:2}" ;; | |
*.gz) pigz -kvr $2 "${args[@]:2}" ;; | |
*.lzma) lzma -kv $2 "${args[@]:2}" ;; | |
# LZMA, LZIP, 7zip e XZ usam o mesmo algoritmo. O 7zip introduziu | |
# o LZMA2 em 2009. O XZ é uma implementação do 7zip. O LZMA foi | |
# descontinuado no Linux em favor do novo XZ. Especialistas dizem | |
# para não usar o XZ para backup de longo prazo, recomendando o | |
# bzip2 no lugar. | |
*.lzip | *.lz) | |
plzip -vo $2 "${args[@]:2}" ;; # Multithreading if plzip is installed | |
*.lzop | *.lzo) | |
lzop -Pvo $2 "${args[@]:2}" ;; | |
*.xz) xz -kv -T0 $2 "${args[@]:2}" ;; # Multithreading through option -T0 | |
*.z) compress -vr $2 "${args[@]:2}" ;; | |
*.zstd | *.zst) | |
zstd -vo $2 "${args[@]:2}" ;; | |
# Binary II e ShrinkIt | |
*.shk | *.sdk) | |
nulib2 -aee $2 "${args[@]:2}" ;; | |
# OUTROS CASOS | |
*) echo "ERRO: '$2' - formato não suportado" ;; | |
esac | |
# Se o parâmetro for -d ou -x, descompactar | |
elif [[ $1 == "-d" || $1 == "d" || $1 == "-x" || $1 == "x" ]]; then | |
# PROBLEMAS: resolver nomes com "-" no 7z e outros | |
# Se o arquivo existir | |
if [ -f $2 ]; then | |
a=$(echo "$2" | awk '{print tolower($0)}') | |
case $a in | |
# TAR supported formats | |
*.tar) tar -xvpf $2 ;; | |
*.tar.bz2 | *.tbz2 | *.tbz | *.tb2) | |
tar -I pbzip2 -xvpf $2 ;; # Multithreading through pbzip2 | |
*.tar.gz | *.tgz) | |
tar -I pigz -xvpf $2 ;; # DON'T SUPPORT MT | |
*.tar.lzip | *.tar.lz | *.tlz) | |
tar -I plzip -xvpf $2 ;; # Multithreading through plzip | |
*.tar.xz | *.txz) | |
tar -I 'unxz -vv -T0' -xvpf $2 ;; # DON'T SUPPORT MT | |
*.tar.lzma | *.tar.lzo | *.tzo | *.tar.zst | *.tzst) | |
tar -xvpaf $2 ;; | |
*.tar.7z) | |
7z x $2 && tar -xvpf "${2%.*}" ;; # DON'T SUPPORT MT | |
# NON-TAR | |
*.7z) 7z x $2 ;; # DON'T SUPPORT MT | |
*.arj) arj x -y $2 ;; | |
*.br) brotli -d $2 ;; # DON'T SUPPORT MT | |
*.bz2 | *.bz) bunzip2 $2 ;; | |
*.cab | *.exe) cabextract $2 ;; | |
*.gz) gunzip $2 ;; | |
*.lzma) unlzma $2 ;; | |
*.lz) plzip -kvd $2 ;; # Multithreading if plzip is installed | |
*.lzo) lzop -vPd $2 ;; | |
*.rar) unrar x -ad $2 ;; # Multithreading by default | |
*.xz) unxz -v -T0 $2 ;; # DON'T SUPPORT MT | |
*.zip) unzip $2 ;; | |
*.zpaq) zpaq x $2 ;; # Multithreading by default | |
*.zst) zstd -vd $2 ;; | |
*.z) uncompress $2 ;; | |
# Binary II e ShrinkIt | |
*.bny | *.bqy | *.bse | *.bxy | *.sdk | *.sea | *.shk) | |
nulib2 -xee $2 "${args[@]:2}" ;; | |
# IMAGENS | |
*.iso | *.bin | *.mdf | *.nrg | *.cdi) | |
unar $2 ;; # DON'T SUPPORT MT | |
# INCOMUNS | |
*.sit | *.sitx | *.ace | *.lha | *.lzh | *.lzx | *.cpio | *.pit | *.arc | *.pak) | |
unar $2 ;; # DON'T SUPPORT MT | |
# OUTROS CASOS | |
*) echo "ERRO: '$2' - formato não suportado" ;; | |
esac | |
else | |
echo "ERRO: $2 - arquivo inexistente" | |
fi | |
# Exibe ajuda caso nenhum parâmetro seja fornecido | |
else | |
echo -e "Uso: zap [opção] [caminho/arquivo.extensão] [arquivos e pastas a compactar] | |
ZAP é um wrapper para compactação e descompactação de arquivos em diversos | |
formatos. Ele permite usar apenas as opções básicas de cada programa (verbose e | |
recursividade quando disponíveis) mas carece de opções como listagem (-l), | |
atualização (geralmente -u), níveis de compressão (1..9) etc. | |
Opções: | |
c, -c | |
Compactação. | |
x, -x, d, -d | |
Sinônimos para eXtração ou Descompactação. | |
Formatos suportados: | |
7ZIP (7z, tar.7z) | |
ARJ | |
Binary II and ShrinkIt (bny, bqy, bse, bxy, sdk, sea, shk) | |
* BROTLI (br) | |
BZIP2 (bz, bz2, tar.bz2, tbz, tbz2, tb2) | |
* CABINET (cab, exe) | |
GZIP (gz, tar.gz, tgz) | |
* IMAGEM (iso, bin, mdf, nrg, cdi) | |
* INCOMUNS (ace, arc, cpio, lha, lzh, lzx, pak, pit, sit, sitx) | |
LZIP (lz, tar.lz, tlz) | |
LZMA (lzma, tar.lzma) | |
LZOP (lzo, tar.lzo, tzo) | |
RAR | |
TAR | |
Unix GNUzip (z) | |
XZIP (xz, tar.xz, txz) | |
ZIP | |
ZPAQ | |
Zstandard or Zstd (zst, tar.zst, tzst) | |
* descompressão apenas | |
" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment