Skip to content

zshrc: simple-extract() use unp for all archive types #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 5 additions & 118 deletions etc/zsh/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -3329,97 +3329,12 @@ function trans () {
function simple-extract () {
emulate -L zsh
setopt extended_glob noclobber
local ARCHIVE DELETE_ORIGINAL DECOMP_CMD USES_STDIN USES_STDOUT GZTARGET WGET_CMD
local ARCHIVE DELETE_ORIGINAL DECOMP_CMD WGET_CMD
local RC=0
# Use unp for all archive types
DECOMP_CMD="unp"
zparseopts -D -E "d=DELETE_ORIGINAL"
for ARCHIVE in "${@}"; do
case $ARCHIVE in
*(tar.bz2|tbz2|tbz))
DECOMP_CMD="tar -xvjf -"
USES_STDIN=true
USES_STDOUT=false
;;
*(tar.gz|tgz))
DECOMP_CMD="tar -xvzf -"
USES_STDIN=true
USES_STDOUT=false
;;
*(tar.xz|txz|tar.lzma))
DECOMP_CMD="tar -xvJf -"
USES_STDIN=true
USES_STDOUT=false
;;
*tar.zst)
DECOMP_CMD="tar --zstd -xvf -"
USES_STDIN=true
USES_STDOUT=false
;;
*tar.lrz)
DECOMP_CMD="lrzuntar"
USES_STDIN=false
USES_STDOUT=false
;;
*tar)
DECOMP_CMD="tar -xvf -"
USES_STDIN=true
USES_STDOUT=false
;;
*rar)
DECOMP_CMD="unrar x"
USES_STDIN=false
USES_STDOUT=false
;;
*lzh)
DECOMP_CMD="lha x"
USES_STDIN=false
USES_STDOUT=false
;;
*7z)
DECOMP_CMD="7z x"
USES_STDIN=false
USES_STDOUT=false
;;
*(zip|jar))
DECOMP_CMD="unzip"
USES_STDIN=false
USES_STDOUT=false
;;
*deb)
DECOMP_CMD="ar -x"
USES_STDIN=false
USES_STDOUT=false
;;
*bz2)
DECOMP_CMD="bzip2 -d -c -"
USES_STDIN=true
USES_STDOUT=true
;;
*(gz|Z))
DECOMP_CMD="gzip -d -c -"
USES_STDIN=true
USES_STDOUT=true
;;
*(xz|lzma))
DECOMP_CMD="xz -d -c -"
USES_STDIN=true
USES_STDOUT=true
;;
*zst)
DECOMP_CMD="zstd -d -c -"
USES_STDIN=true
USES_STDOUT=true
;;
*lrz)
DECOMP_CMD="lrunzip -"
USES_STDIN=true
USES_STDOUT=true
;;
*)
print "ERROR: '$ARCHIVE' has unrecognized archive type." >&2
RC=$((RC+1))
continue
;;
esac

if ! check_com ${DECOMP_CMD[(w)1]}; then
echo "ERROR: ${DECOMP_CMD[(w)1]} not installed." >&2
Expand All @@ -3429,21 +3344,7 @@ function simple-extract () {

GZTARGET="${ARCHIVE:t:r}"
if [[ -f $ARCHIVE ]] ; then

print "Extracting '$ARCHIVE' ..."
if $USES_STDIN; then
if $USES_STDOUT; then
${=DECOMP_CMD} < "$ARCHIVE" > $GZTARGET
else
${=DECOMP_CMD} < "$ARCHIVE"
fi
else
if $USES_STDOUT; then
${=DECOMP_CMD} "$ARCHIVE" > $GZTARGET
else
${=DECOMP_CMD} "$ARCHIVE"
fi
fi
${=DECOMP_CMD} "$ARCHIVE"
[[ $? -eq 0 && -n "$DELETE_ORIGINAL" ]] && rm -f "$ARCHIVE"

elif [[ "$ARCHIVE" == (#s)(https|http|ftp)://* ]] ; then
Expand All @@ -3459,21 +3360,7 @@ function simple-extract () {
continue
fi
print "Downloading and Extracting '$ARCHIVE' ..."
if $USES_STDIN; then
if $USES_STDOUT; then
${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD} > $GZTARGET
RC=$((RC+$?))
else
${=WGET_CMD} "$ARCHIVE" | ${=DECOMP_CMD}
RC=$((RC+$?))
fi
else
if $USES_STDOUT; then
${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE") > $GZTARGET
else
${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE")
fi
fi
${=DECOMP_CMD} =(${=WGET_CMD} "$ARCHIVE")

else
print "ERROR: '$ARCHIVE' is neither a valid file nor a supported URI." >&2
Expand Down