bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Add new program: magic


From: Bo Borgerson
Subject: [PATCH] Add new program: magic
Date: Wed, 9 Apr 2008 20:13:28 -0400

Hi,

As I mentioned last week, I've patched my local `sort' to allow
automatic decompression of input files if an option, --magic-open, is
passed on the command line.

As I thought more about this functionality I realized that it may be
more broadly useful.  Any utility that can operate on multiple input
files could benefit.  I wondered if it would be possible in a
non-invasive way to provide this service to other tools.  This is what
I came up with.

Instead of:
$ sort --magic-open a.gz b.bz2 c.txt

I run:
$ magic sort a.gz b.bz2 c.txt

This creates a temporary fifo and opens a decompression program for
each compressed input.  The corresponding files in the argument list
are replaced by these temporary fifos.  When the command completes,
the fifos are removed.  If a signal is received and execution is
terminated prematurely, the fifos are removed.

Then I realized that this automatic fifo management might be more
useful still.  In addition to checking the `magic' bytes at the
beginning of regular files for known decompression programs, I thought
it might be useful to allow an arbitrary sub-command to be used as an
input.

For example, to compare the output of two versions of a program:
$ magic diff "ls -l" "src/ls -l"

Or to compare files on two remote machines:
$ magic diff "ssh host1 cat /etc/passwd" "ssh host2 cat /etc/passwd"

I've attached a basic implementation of this tool.  It supports both
magic-number-based auto-decompression of known formats and sub-command
inputs through auto-maintained fifos.  It supports both command-line
argument interpretation and --files0-from=F interpretation.  It
supports explicit directives to override interpretation precedence.

Is this something that might be worth including in coreutils?

Thanks,

Bo

Attachment: coreutils-magic.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]