Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "unarchive" script/function?



On 2009-01-07 11:18:38 -0500, TjL wrote:
> Basically I want to be able to throw any kind of archive/compression
> method and have them all dealt with, so I could theoretically do this:
> 
>          unarchive file1.zip file2.tar file3.tbz file4.tar.gz
> 
> and the "unarchive' program would know what to do with each.

FYI, I have in my .zshrc:

unarch()
{
  local file decomp
  for file in $@
  do
    unset decomp
    [[ ( $file:e == gz && $file:r:e == tar ) || $file:e == tgz ]] \
      && decomp=gunzip
    [[ $file:e == bz2 && $file:r:e == tar ]] \
      && decomp=bunzip2
    [[ $file:e == lzma && $file:r:e == tar ]] \
      && decomp=unlzma
    if [[ -z $decomp ]] then
      echo "Usage: $0 [ \033[4mtgz-file\033[m | \033[4mbz2-file\033[m ] | \033[4mlzma-file\033[m ] ..." >&2
      return 1
    fi
    if [[ -r $file ]] then
      echo "$0 $file ..."
      $decomp $file -c | tar xf -
    else
      echo "$0: $file is not readable" >&2
    fi
  done
}

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author