[linux-elitists] speaking of mind-reading...

Adam Sampson azz@gnu.org
Tue Jan 15 01:09:26 PST 2002


Rob Walker <rob@myinternetplace.net> writes:

> Does anyone know why gnutar doesn't just look at the file and then
> pipe it through gzip or bzip2 as appropriate?

Dunno, but I wrote tart a while back, and have "t" and "x" aliased to
"tart t" and "tart x" respectively. Handles multiple archives too.

#!/bin/sh
# tart - an lha-style tar frontend
# Usage: tart [tx] archivefiles ...
# For best effect, "alias x='tart x'; alias t='tart t'" in your sh;
# you can then "x RandomArchive.tar.bz2 somearc.tar.gz"...
# Adam Sampson, azz@gnu.org
todo=$1
shift
for x in $* ; do
	prefix=''
	type=`file "$x"`
	if echo $type | grep -q "gzip compressed" ; then
		prefix='gunzip |'
		type=`gunzip <"$x" | file -`
	fi
	if echo $type | grep -q "compress'd data" ; then
		prefix='uncompress |'
		type=`uncompress <"$x" | file -`
	fi
	if echo $type | grep -q "bzip2 compressed" ; then
		prefix='bunzip2 |'
		type=`bunzip2 <"$x" | file -`
	fi
	if echo $type | grep -q "tar archive" ; then
		archiver='tar'
	fi
	cmd='echo Uh...'
	case $todo in
	t)
		case $archiver in
		tar)
			cmd='tar tvf -'
			;;
		esac
		;;
	x)
		case $archiver in
		tar)
			cmd='tar xvf -'
			;;
		esac
		;;
	esac
	eval "cat $x | $prefix $cmd"
done

-- 
Adam Sampson <azz@gnu.org>                  <URL:http://azz.us-lot.org/>



More information about the linux-elitists mailing list