Re: [dev] [wmii] wimenu custom completion

From: Kris Maglione <maglione.k_AT_gmail.com>
Date: Thu, 12 Aug 2010 22:21:54 -0400

On Thu, Aug 12, 2010 at 09:19:52PM -0400, Kris Maglione wrote:
> Yes... Unfortunately awk dies on SIGPIPE in that example, so it never
> runs the END block. This slight variation should work:
>
> wimenu -c <fifo | awk '
> BEGIN {
> # Define the completion results
> cmds = "foo\nbar\nbaz\n"
> cmd["foo"] = "1\n2\n3\n"
> cmd["bar"] = "4\n5\n6\n"
> cmd["baz"] = "7\n8\n9\n"
> # Print the first set of completions to wimenu’s fifo
> fifo = "fifo"
> print cmds >fifo; fflush(fifo)
> }
>
> //
>
> # Push out a new set of completions
> function update(str, opts) {
> print length(str) >fifo # Print the length of the preceding string
> print opts >fifo # and the options themself
> fflush(fifo)
> }
>
> # Ensure correct argument count with trailing spaces
> / $/ { $0 = $0 "#"; }
> { # Process the input and provide the completions
> if (NF == 1)
> update("", cmds) # The first arg, command choices
> else
> update($1 " ", cmd[$1]) # The second arg, command arguments
> # Skip the trailing part of the command
> getline rest
> }
> ' | tail -1

Oh, but I notice that this doesn't work with gawk. You'll need
to replace the // line with { print; fllush() }. I'm afraid that
if you use mawk it's hopeless.

-- 
Kris Maglione
If you think your management doesn't know what it's doing or that your
organisation turns out low-quality software crap that embarrasses you,
then leave.
	--Edward Yourdon
Received on Fri Aug 13 2010 - 04:21:54 CEST

This archive was generated by hypermail 2.2.0 : Fri Aug 13 2010 - 04:24:02 CEST