From 025de6fc5b09c46c5075bb673f659c639b30f1ba Mon Sep 17 00:00:00 2001 From: xHyroM Date: Sun, 27 Aug 2023 17:32:32 +0200 Subject: [PATCH] feat: extract script finally i dont need to remember all commands --- .local/bin/ex | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 .local/bin/ex diff --git a/.local/bin/ex b/.local/bin/ex new file mode 100755 index 0000000..e07ea43 --- /dev/null +++ b/.local/bin/ex @@ -0,0 +1,50 @@ +#!/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 -o $extraction_folder;; + *) + echo "'$1' cannot be extracted via ex()";; +esac