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

Re: "unarchive" script/function?



* Vincent Lefevre <vincent@xxxxxxxxxx> typed:
> 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
> }

I use Çnp(1) (<http://packages.debian.org/etch/unp>); it's a perl script
which runs the correct unpack program depending on the file extension of
the given parameter. HTH
-- 
"Another world, another day, another dawn. "



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