On 10/6/06, Philip Ganchev <[EMAIL PROTECTED]> wrote:
> On 10/4/06, Axel Liljencrantz <[EMAIL PROTECTED]> wrote:
> > On 10/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > > On 9/28/06, Myrddin Emrys <[EMAIL PROTECTED]> wrote:
> > > > On 9/28/06, Philip Ganchev <[EMAIL PROTECTED]> wrote:
> > > > > On 9/22/06, Myrddin Emrys <[EMAIL PROTECTED]> wrote:
> > > > Yes, a set of switches that work together, separate from other
> > > > switches. An example is the  Gentoo utility 'emerge', or the Redhat
> > > > utility 'rpm'. They have modes with completely separate functionality,
> > > > and switches that only apply to one mode or the other. Another example
> > > > might be the old DOS pkzip app, which had zipping and unzipping in one
> > > > command (unlike the freenix convention of separating the two apps).
> > >
> > > As I understand, ``complete'' cannot capture those anyway, so you
> > > don't lose anything.
> >
> > It can and it does. For a simple example, try to complete the command
> > 'set LANG en_', and you will get a list of english locales. Try
> > completing 'set fish_color_pwd b' and you will get a list of colors
> > beginning with 'b'. Other commands that do this include 'rpm',
> > 'darcs', 'cvs' and 'svn'.
>
> Oh, I did not see that in the help.  So how can I specify that you
> can't write ``set --local --global x y''?  I think that's what Myrddin
> meant.

The syntax for doing this is pretty general purpose, so to do this,
you have to use it in combination with a few other commands.

You use the -n switch to specify a condition, which is a command that
will be executed and it's exit status will determine if the completion
will be used:

complete -n "false" -c set -l global -d (N_ "Global scope" )

The above will always evaluate to false, so the completion will never be used.

Now, one has to write a little script to check the arguemnts already
given to the current command, and check if '--local' '-l'-
'--universal' or '-U' is one of them. This is done using the
'commandline' builtin. Fortunatly, a function that does this has
already been written, and it is distributed with fish. It's called
__fish_contains_opt. The '__fish_' prefix signifies that the function
may be changed in the future. Anyway, in the example above, the way to
specify what switches are allowed would be:

complete -n "not __fish_contains_opt -s U -s l local universal" -c set
-l global -d (N_ "Global scope" )

At first, I was afraid that the -n switch might be to general purpose
and hence difficult to use, but actually, when looking over the uses
of the -n switch, they are very diverse.

>
> > Also, the completions for commands which run other commands, like
> > 'time' or 'sudo' use this kind of functionality as well.
> >
> > >
> > > Ideally, ``complete'' should be able to understand a synopsys of a
> > > command.  Then the synopsis itself can be automatically parsed from
> > > the man page too.
> >
> > The synopsis is already in the whatis database, so there should be no
> > need for this.
>
> Oh, good.  I'd like to think you mean no need for parsing, but I have
> a nagging suspicion that you mean no need for complete to understand
> the synopsis.  I was thinking the synopsys would be useful in two
> ways.

Sorry, I misread. I read 'synopsis' as 'summary'.

> 1.  "compete" would know exactly what combinations and order of
> options are acceptable.  People have gone to the trouble of defining
> and documenting this, why not use it interactively?
> 2.  while entering options of a command, the user would see what order
> and combinations of optoins are allowed.  It's the same benefit as in
> the man page but much more handy since the user does not have to
> interrupt entering the command to invoke ``man''.
>

These would be cool. Sounds pretty hard to do, though. But on the plus
side, this ahould be implemented as an external command, meaning it
could be done in Python or another high level language, if you don't
like C. *hint* :-)

-- 
Axel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to