From 47aa19ecf83d776d4e5ef07561eefb323f04ba1d Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 6 Feb 2020 20:25:54 +0100 Subject: [PATCH] *install: FEATURE: zpextract's --auto mode now also uses the `file' tool MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to search for the archives – no extension is needed! Use this e.g.: with an id-as=a-word snippets to have the target file (i.e.: `a-word`) correctly extracted. --- zinit-install.zsh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/zinit-install.zsh b/zinit-install.zsh index b62cad0a..4957a738 100644 --- a/zinit-install.zsh +++ b/zinit-install.zsh @@ -1273,6 +1273,36 @@ ziextract() { ziextract "$file" $opt_move $opt_norm ret_val+=$? } + # Second, try to find the archive via `file' tool + if (( !${#files} )) { + local -a output + output=( ${(@f)"$(command file -- **/*~(._zinit|.zinit_lastupd|._backup|.git)(|/*)(DN) 2>&1)"} ) + for file ( $output ) { + local fname=${file%:*} desc=${file##*:} type + type=${(L)desc/(#b)(#i)* (zip|rar|gzip|bzip2|tar) */$match[1]} + if [[ $type = (zip|rar|gzip|bzip2|tar) ]]; then + print -Pr -- "${ZINIT[col-pre]}ziextract:${ZINIT[col-info2]}" \ + "Note:${ZINIT[col-rst]}" \ + "detected a ${ZINIT[col-obj]}$type${ZINIT[col-rst]}" \ + "archive in the file ${ZINIT[col-file]}$fname" \ + "${ZINIT[col-rst]}" + ziextract "$fname" "$type" $opt_move $opt_norm + ret_val+=$? + + # Support nested tar.(bz2|gz|…) archives + [[ -f $fname.out ]] && fname=$fname.out + if [[ -f $fname ]] { + output=( ${(@f)"$(command file -- "$fname" 2>&1)"} ) + fname=${output[1]%:*} desc=${output[1]##*:} + type=${(L)desc/(#b)(#i)* (zip|rar|gzip|bzip2|tar) */$match[1]} + if [[ $type = (zip|rar|gzip|bzip2|tar) ]] { + ziextract "$fname" "$type" $opt_move $opt_norm + ret_val+=$? + } + } + fi + } + } return $ret_val }