zsh-users
 help / color / mirror / code / Atom feed
* Pax completion?
@ 2003-04-09 19:41 The Matt
  2003-04-16  9:37 ` Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: The Matt @ 2003-04-09 19:41 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1065 bytes --]

Folks, I was wondering if anyone out there has made completion bits for
pax, the portable archiver?  I'm not a hacker, so once I looked at the
_cpio and _tar functions, I was kinda scared to build my own.  (The bash
completion project also doesn't have the pax so I can't try to copy
theirs.)

Barring anyone actually having one, how would I go about associating pax
with at least the file types I use it for (*.pax, .tar, .tar.gz, .cpio,
&c.).  Would something like:

compctl -g '*.(cpio|tar|pax) pax -f

work?  And is there a similar way for pax -zf to expand for .pax and
.tar.gz files?  Or should I buckle down and try to bring together the
_cpio and _tar* into one _pax?

Sorry for the n00b question, but this is the first time I've tried
adding onto the completion.

Thanks,
Matt Thompson
-- 
"And isn't sanity really just a one-trick pony, anyway?  I mean,
all you get is one trick, rational thinking, but when you're good
and crazy, ooh ooh ooh, the sky's the limit!" -- The Tick
  The Matt -- http://ucsub.colorado.edu/~thompsma/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Pax completion?
  2003-04-09 19:41 Pax completion? The Matt
@ 2003-04-16  9:37 ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2003-04-16  9:37 UTC (permalink / raw)
  To: The Matt; +Cc: zsh-users

On 9 Apr, The Matt wrote:
> 
> Folks, I was wondering if anyone out there has made completion bits for
> pax, the portable archiver?  I'm not a hacker, so once I looked at the
> _cpio and _tar functions, I was kinda scared to build my own.  (The bash
> completion project also doesn't have the pax so I can't try to copy
> theirs.)

Don't let the complexity of _tar or _cpio worry you. tar's options are
particulary complicated (-C is especially messy to handle) and the
worst part is handling completion of files inside an archive. It
shouldn't be hard to write basic pax completion that does most of what
you want.

> Barring anyone actually having one, how would I go about associating pax
> with at least the file types I use it for (*.pax, .tar, .tar.gz, .cpio,

  _pax() { _files -g '*.(tar|pax|cpio|tar.gz)' }
  compdef _pax pax

would do the job. Or in zsh 4.1, you can do:

  compdef "_files -g '*.(tar|pax|cpio|tar.gz)'" pax

> &c.).  Would something like:
> 
> compctl -g '*.(cpio|tar|pax) pax -f
> 

The final `-f' wouldn't do what you think but with slight changes that
would roughly work. I'd advise using compdef instead though.

To write a decent pax completion, I'd suggest starting by getting the
options together using _arguments. As a start, you might have:

_arguments -s \
  '(-a -w)-r[extract from archive]' \
  '(-a -r)-w[write to archive]' \
  '(-r -w)-a[append files to end of archive]' \
  '-b+[specify block size]:block size' \
  '-x+[specify output archive format]:archive format:(cpio bcpio sv4cpio sv4crc tar ustar)'

For the -f option, it would be something like:
  '-f+[specifiy archive file]:archive file:_files -g "*.(pax|tar|cpio)"'

> work?  And is there a similar way for pax -zf to expand for .pax and

Getting it to detect a -z option for gzip is not trivial however. You
could check for -z manually in $words (which is what _tar does) but it
is more reliable to use _argument's opt_args association which is set
to the options which have been specified on the line.

The following works by appending (|.gz) to the glob if it finds the -z
option.

  '-f+[specifiy archive file]:archive file:_files -g "*.(pax|tar|cpio)${opt_args[(I)-z]\:+(|.gz)}"'

> .tar.gz files?  Or should I buckle down and try to bring together the
> _cpio and _tar* into one _pax?

You'd find it easier starting from scratch. _zip is probably a simpler
example of this sort of stuff - _tar is one of the oldest functions.
And if you run into problems, you can always ask here.

Oliver


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-16  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 19:41 Pax completion? The Matt
2003-04-16  9:37 ` Oliver Kiddle

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).