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

Re: Another tar-completion function



Peter Stephenson (pws@xxxxxx) wrote:
> Here is my completion function for extracting individual files from a
> tar archive.  I realise there are others around with different
> argument handling, which look for a -f argument to find the archive
> name, for example, whereas this simply assumes the options are all in
> the first argument and the archive is the second.  This just happens
> to fit my normal usage.

I thought I'd post my version as there's a vague chance someone
might benefit from it.  I very much doubt it's quite as nice as
yours (I haven't got time to examine yours in close detail), but
I think it does roughly the same thing and doesn't have the
problem where you have to backspace every time it inserts a
directory.


-------- 8< -------- 8< --------

# General function for completing (symlinks to) directories, and
# files matching a glob pattern supplied as second argument.
# First argument is the prefix passed directly from -K.  I think
# it has to be done in stages using files2 and links2 because
# funny things happen if you try to do too much expansion and
# interpolation all at once.

compctl_dfl () {
	local dirs files files2 links links2
	dirs=( $1*(/N) )
	files=( $1$2(N) )
	links=( $1*(@N) )
	files2=( ${^files}" " )
	links2=( ${^links}"/" )
	reply=( ${dirs:-''} ${links2:-''} ${files:-''} )
}

# Functions called directly from compctl

compctl_targz () {
	compctl_dfl ${1:-''} "*.(tar.gz|t[ag]z|tar.Z|tz|tarZ)"
}

compctl_tar () {
	compctl_dfl ${1:-''} "*.tar"
}

# And here's the compctl:

compctl -f -g '*(-/)' -x 'p[1],s[-]' -k '(ztvf zcvf zxvf tvf cvf xvf -ztvf -zcvf -zxvf -tvf -cvf -xvf)' - 'W[1,*c*]' -f -g '*(-/)' - 'W[1,*(z*f|f*z)*] p[2]' -K compctl_targz -Q -S '' - 'W[1,*f*] p[2]' -K compctl_tar -Q -S '' -- gnutar gtar tar

-------- 8< -------- 8< --------

It could be laughably wrong but it works for me :-)

If any of the /real/ zsh gurus (I'm just a newbie) would care to
comment then please do.

Will there be a new zefram release or something soon that will
render all this hackery unnecessary?

--
Adam Spiers, Computing Officer, New College, Oxford University, UK **
violoncello/modern jazz/juggling/cycling/Perl/Linux fanatic, M$ hater
e-mail: adam.spiers@xxxxxxxxxxxx  WWW: http://www.new.ox.ac.uk/~adam/



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