Last active
May 19, 2024 20:46
-
-
Save yunginnanet/b1595f5c37253532ba975029f8336fbe to your computer and use it in GitHub Desktop.
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 bash | |
function _getExt() { | |
echo "$@" | awk -F '.' '{print $NF}' | |
} | |
function _getArchiveName() { | |
_ext="$(_getExt "$@")" | |
_name="${*/.$_ext//}" | |
_name="${_name//\//}" | |
echo "$_name" | |
} | |
function xtract() { | |
_target="$(_getArchiveName "$@")" | |
echo "$_target" | |
mkdir "$_target" || return 1 | |
cd "$_target" || return 1 | |
mv "../$*" ./ || return 1 | |
7z x "$*" || return 1 | |
if ! [[ "$(_getExt "$@")" = "tar" ]]; then | |
(7z x ./*.tar && rm ./*.tar) &>/dev/null | |
fi | |
cd .. | |
} | |
function xtract_all { | |
for format in {zip,rar,tgz,tar,7z,tar.gz,gz,bz2,lzma,xz}; do | |
for archive in ./*."$format"; do | |
if ! /bin/ls "$archive" 2>/dev/null; then continue; fi | |
echo "$archive" | |
xtract "${archive//\.\//}" | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment