#!/bin/zsh if [[ -z $1 ]]; then echo "Please provide a file to extract." exit 1 fi if [[ ! -f $1 ]]; then echo "'$1' is not a valid file" exit 1 fi if [[ -z $2 ]]; then extraction_folder="." else extraction_folder="$2" fi if [[ ! -d $extraction_folder ]]; then mkdir -p $extraction_folder fi case $1 in *.tar.bz2|*.tbz2) tar -xjf $1 -C $extraction_folder;; *.tar.gz|*.tgz) tar -xzf $1 -C $extraction_folder;; *.bz2) bunzip2 $1 -c > $extraction_folder/$(basename $1 .bz2);; *.rar) unrar x $1 $extraction_folder;; *.gz) gunzip $1 -c > $extraction_folder/$(basename $1 .gz);; *.tar) tar -xf $1 -C $extraction_folder;; *.zip) unzip $1 -d $extraction_folder;; *.Z) uncompress $1 -c > $extraction_folder/$(basename $1 .Z);; *.7z) 7z x $1 -o$extraction_folder;; *.deb) ar x $1 -C $extraction_folder;; *.tar.xz) tar -xf $1 -C $extraction_folder;; *.tar.zst) unzstd $1;; *.tar.lz) tar --lzip -xf $1 -C $extraction_folder;; *.tar.lzop) lzop -d $1 -o $extraction_folder/$(basename $1 .lzop);; *.bz3) bunzip3 $1 -c > $extraction_folder/$(basename $1 .bz3);; *.a) ar -x $1;; *.lz) lzip -d $1 -o $extraction_folder/$(basename $1 .lz);; *.lzo) lzop -d $1 -o $extraction_folder/$(basename $1 .lzo);; *.lz4) lz4 -d $1;; *.lrz) lrz -d $1 -o $extraction_folder/$(basename $1 .lrz);; *.shar) unshar $1;; *.xz) xz -d $1;; *.zst) zstd -d $1 -o $extraction_folder/$(basename $1 .zst);; *.cpio) cpio -idmv < $1;; *) echo "'$1' cannot be extracted via ex()" exit 1;; esac