mirror of
https://github.com/xHyroM/dotfiles.git
synced 2024-11-10 01:18:06 +01:00
50 lines
1.1 KiB
Bash
Executable file
50 lines
1.1 KiB
Bash
Executable file
#!/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
|