zsh-users
 help / color / mirror / code / Atom feed
* need completion help....
@ 1999-04-17 20:51 Timothy J Luoma
  1999-04-17 21:00 ` Sorry, left out an important detail >> " Timothy J Luoma
  0 siblings, 1 reply; 3+ messages in thread
From: Timothy J Luoma @ 1999-04-17 20:51 UTC (permalink / raw)
  To: zsh-users


*sigh*

I don't understand completion at all.

Here's what I need.  I need completions for a command "mva"

mva will move files from the directory $asub

	BUT it needs to ignore any files which begin with
		the letters "README" (all in capitals, may not be
		any more letters than just "README" or can be
		any length after that
	   AND files named 'files.html' and 'index'		

Here's the folder's current contents:

# ls $asub
README@
README-Naming-MacOS-X-Submissions
README_How-to-Write-a-Good-README
README_Understanding-How-Files-are-Named
files.html
index
squid-2.1.PATCH2-P-b.gnutar.gz
squid-2.1.PATCH2-P-s.gnutar.gz
squid-2.1.PATCH2.README
ssh-2.0.12-P-b.gnutar.gz
ssh-2.0.12-P-s.gnutar.gz
ssh-2.0.12.README

In this example, the squid? files and the ssh? files are the only ones I  
would want completions for when I do:

	mva [tabhere]

can someone help me out?  I've looked over tons of examples, but I just get  
more and more confused.

TjL

	


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

* Sorry, left out an important detail >> Re: need completion help....
  1999-04-17 20:51 need completion help Timothy J Luoma
@ 1999-04-17 21:00 ` Timothy J Luoma
  1999-04-18  0:49   ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Timothy J Luoma @ 1999-04-17 21:00 UTC (permalink / raw)
  To: zsh-users


OK, here's what I have:

function asubfiles ()
{
    reply=( $(/bin/ls $asub |\
                egrep -v "README*|files.html|index") )
}


compctl -K asubfiles  'S[-]' -- mva


but the problem is that I want to use the command like this:

mva [tab here to get files in $asub] ../[tab here to get list of directories 
	in parent directory, which will always be the contents of the
	folder $new]

my completion attempt above gives me the 1st part, tab here to get files in  
$asub, but doesn't give me the ability to tab for directories.

That's what I need help with.

Sorry for being unclear.

TjL



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

* Re: need completion help....
  1999-04-17 21:00 ` Sorry, left out an important detail >> " Timothy J Luoma
@ 1999-04-18  0:49   ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1999-04-18  0:49 UTC (permalink / raw)
  To: Timothy J Luoma, zsh-users

On Apr 17,  4:51pm, Timothy J Luoma wrote:
: Subject: need completion help....
:
: I don't understand completion at all.

You probably aren't alone.

: mva will move files from the directory $asub
: 
: 	BUT it needs to ignore any files which begin with
: 		the letters "README" (all in capitals, may not be
: 		any more letters than just "README" or can be
: 		any length after that
: 	   AND files named 'files.html' and 'index'		
: 
: but the problem is that I want to use the command like this:
: 
: mva [tab here to get files in $asub] ../[tab here to get list of directories 
: 	in parent directory, which will always be the contents of the
: 	folder $new]

I'm going to ignore $new and ../, and just deal with one of the arguments
giving the name of a directory.

One way to reason about this is as follows:

You have a command (mva) that needs to complete in two different ways --
(1) relative to $asub and (2) relative to a directory prefix you supply
on the command line.

The simple built-in complctl options are able to complete only one way
(per option, of course).  That is, if you use only simple compctls, all
the options are tried for whatever word the cursor is on, no matter what
that word "looks like"; but you need different options to be tried on
different words.

So you need to either (a) use a function with -K that will figure out
which of the two cases is appropriate, or (b) use extended completion.
(With the new completion patches for 3.1.5, there are more ways to use
a function, but it still comes down to either a function or extended
completion.)

Extended completion is appropriate if the rules for determining which
way to complete can be expressed as simple patterns.  In the case you
describe, the rules might be something like "if the current word has a
slash in it, complete directories using the word so far as the path to
those directories; otherwise complete files in $asub".  The first part
is easily expressed in extended completion patterns; but there's no way
to expand $asub at completion time except with a function, so you're
going to have to have a -K function anyway.  So it's a toss-up in this
case whether you want to try extended completion (unless $asub never
changes during a shell session).

Supposing you want to try extended completion, it would look something
like this (3.0.5 syntax):

    compctl -K asubfiles -x 'C[0,*/*]' -g '*(D/)' -- mva

(In 3.1.4+, use -/ instead of -g '*(D/)', for better results.)

The part before the -x is what's tried if none of the patterns after
the -x match the current line.  The C[0,*/*] means "count 0 words from
the current word, and then compare the word you get to */*".  If that
pattern matches, -g means use a glob pattern (which is attached to the
end of the selected word), and *(D/) means match directories including
those whose names begin with a dot.

Now, what about the asubfiles function?

: OK, here's what I have:
: 
: function asubfiles ()
: {
:     reply=( $(/bin/ls $asub |\
:                 egrep -v "README*|files.html|index") )
: }

That actually would probably work OK, though you might want "/bin/ls -1"
(that's "dash one") to be sure there's only one file per line.  However,
it might be better to do the whole thing with globbing like so:

    function asubfiles ()
    {
	setopt localoptions extendedglob nocshnullglob nullglob
	reply=( $asub/*~*/(README*|files.html|index) )
	reply=( $reply:t )
    }

You need extendedglob to get the ~ in the middle to mean "discard any
file names that match the following pattern".  The other two options
are just to prevent "no match" errors in case $asub is empty.

: compctl -K asubfiles  'S[-]' -- mva

I'm not sure what you were trying to do here ... I think there should be
a -x in front of 'S[-]' and something between 'S[-]' and --, but from
what you told us I don't know what goes there.  Does mva have any command
line options?

: Sorry for being unclear.

No problem.

Oh, supposing you had wanted to try this only with -K, you'd need to do
the pattern matching of the command line words in asubfiles, like this:

    function asubfiles ()
    {
	setopt localoptions extendedglob nocshnullglob nullglob
	case $1$2 in
	*/*) reply=( ${1}*${2}(D/) );;
	*)  reply=( $asub/*~*/(README*|files.html|index) )
	    reply=( $reply:t );;
	esac
    }
    compctl -K asubfiles mva

The $1$2 and ${1}*${2} stuff are to handle completeinword, in case you
have that option set.

The drawback to this is that the completion system doesn't "know" (as
it does with -x ... -g) that the strings returned in $reply in the */*
case are directories; so it won't append a trailing slash and place the
cursor where you can continue completing subdirectories.  Maybe that's
actually the behavior you want, though.

One of the new completion gizmos in the latest 3.1.5 patches is the
ability to tell the completion system that you're returning directory
names, so that it will do the right thing with the trailing slash and
the cursor position.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

end of thread, other threads:[~1999-04-18  0:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-17 20:51 need completion help Timothy J Luoma
1999-04-17 21:00 ` Sorry, left out an important detail >> " Timothy J Luoma
1999-04-18  0:49   ` Bart Schaefer

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).