Linux

tar ballが .gzだろうが.xzだろうが.zstだろうが解凍してやる!

TL;DR #!/bin/bash untar_by_file_type() { if [[ "$1" == "application/x-tar" ]]; then tar -xvf "$2" elif [[ "$1" == "application/gzip" ]]; then tar -zxvf "$2" elif [[ "$1" == "application/x-xz" ]]; then tar -Jxvf "$2" elif [[ "$1" == "application/zstd" ]]; then tar --use-compress-program unzstd -xvf "$2" fi } untar() { if [[ "$1" == "" ]]; then echo "usage: untar <archive-filename>" exit 1 fi untar_by_file_type "$(file -b --mime-type "$1")" "$1"