* completion with descriptions
@ 2006-03-27 13:27 Andy Spiegl
2006-03-27 13:46 ` Peter Stephenson
0 siblings, 1 reply; 4+ messages in thread
From: Andy Spiegl @ 2006-03-27 13:27 UTC (permalink / raw)
To: zsh-users
How can I provide a description for every offered completion
like e.g. "kill" does it nicely?
# kill t<TAB>
process ID
28745 ? 00:02:11 tudu
28760 ? 00:00:00 tail
28879 pts/7 00:02:08 topcpu
28881 pts/8 00:00:08 tmp-cron-script
In my completion function I tried like this:
':cmds: compadd ${${(f)"$(gigaset --commands)"}%%[[:space:]]##--*}' \
but it only gives me this:
# condor:~>gigaset d<TAB>
del demux details dir divx divxfast dump
although "gigaset --commands" outputs:
...
dir -- Liste der Aufnahmen
dump -- Details anzeigen
details -- (s. dump)
divx -- Aufnahme ins DivX-Format konvertieren
divxfast -- Aufnahme (schneller) ins DivX-Format konvertieren
demux -- Aufnahme mit projectX demultiplexen
del -- (s. rm)
...
For the last hours I read the manual and examples (like _pids) but
eventually got lost before finding the solution :-(
Thanks,
Andy.
--
Finagle's First Law:
If an experiment works, something has gone wrong.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion with descriptions
2006-03-27 13:27 completion with descriptions Andy Spiegl
@ 2006-03-27 13:46 ` Peter Stephenson
2006-03-27 16:30 ` Andy Spiegl
0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2006-03-27 13:46 UTC (permalink / raw)
To: zsh-users
Andy Spiegl wrote:
> How can I provide a description for every offered completion
> like e.g. "kill" does it nicely?
>
> In my completion function I tried like this:
> ':cmds: compadd ${${(f)"$(gigaset --commands)"}%%[[:space:]]##--*}' \
You need to use the _describe function; see the zshcompsys manual.
There are examples of this buried in various places. You probably won't
be able to do it inline; you need to create an array with elements
containing both completions and descriptions separated by a colon.
Here's a noddy example.
_foo() {
local -a d
d=(foo:"The word foo" bar:"A rod")
_describe "noddy example" d
}
compdef _foo foo
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion with descriptions
2006-03-27 13:46 ` Peter Stephenson
@ 2006-03-27 16:30 ` Andy Spiegl
2006-03-28 16:35 ` Andy Spiegl
0 siblings, 1 reply; 4+ messages in thread
From: Andy Spiegl @ 2006-03-27 16:30 UTC (permalink / raw)
To: zsh-users
Thank you for the example, Peter!
I tried to dig in deeply into writing completion functions now. :-)
I took _aptitude as a template and came up with the following (see below)
which works as wanted except for the fact that zsh inserts the _whole_ line
(command + description) instead of just the command. *sigh*
Like so:
condor:~>gigaset del\ \ \ \ \ \ \ \ \ --\ Aufnahme\ löschen
gigaset commands
del -- Aufnahme löschen
demux -- Aufnahme mit projectX demultiplexen
details -- Details anzeigen
dir -- Liste der Aufnahmen
dump -- Details anzeigen
mux -- Video+Audio(s) wieder zu einer MPG-Datei multiplexen
title -- Kurzübersicht (Aufnahme-Titel in nur 1 Zeile)
Can someone see where my error is, please?
Here are the relevant parts of the function:
(the whole thing is also here: http://andy.spiegl.de/software/_gigaset)
[...]
_arguments -S \
[...]
'--commands[Liste aller Kommandos]' \
'1: :->cmds' \
'*: :->args'
case $state in
cmds)
cmds=( ${${(M)${(f)"$(gigaset --commands 2>/dev/null)"}:#* -- *}/(#b) (*[^ ]) #-- (*)/$match[1]:$match[2]:l})
_describe -t commands "gigaset commands" cmds && ret=0
;;
args)
[...]
;;
esac
Thx,
Andy.
--
For every problem there is one solution which is simple, neat, and wrong.
-- Henry L. Mencken
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion with descriptions
2006-03-27 16:30 ` Andy Spiegl
@ 2006-03-28 16:35 ` Andy Spiegl
0 siblings, 0 replies; 4+ messages in thread
From: Andy Spiegl @ 2006-03-28 16:35 UTC (permalink / raw)
To: zsh-users
> I took _aptitude as a template and came up with the following (see below)
> which works as wanted except for the fact that zsh inserts the _whole_
> line (command + description) instead of just the command. *sigh*
I solved it!
For the records, the problem was an extra space:
> cmds=( ${${(M)${(f)"$(gigaset --commands 2>/dev/null)"}:#* -- *}/(#b) (*[^ ]) #-- (*)/$match[1]:$match[2]:l})
right here ^^^
because my program doesn't begin the lines (in the list of possible
commands) with a space.
After also deleting the ":l" at the end zsh stopped converting all my
German words to lowercase, oh what wonder. :-)
So this works now beautifully:
cmds=( ${${(M)${(f)"$(gigaset --commands 2>/dev/null)"}:#* -- *}/(#b)(*[^ ]) #-- (*)/$match[1]:$match[2]})
Thanks for all the help,
Andy.
--
"security is an exercise in applied paranoia" -- Unknown
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-03-28 16:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-27 13:27 completion with descriptions Andy Spiegl
2006-03-27 13:46 ` Peter Stephenson
2006-03-27 16:30 ` Andy Spiegl
2006-03-28 16:35 ` Andy Spiegl
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).