Re: [dev] [hack] Having dmenu provide hints about current selected entry

From: Dieter Plaetinck <>
Date: Fri, 26 Nov 2010 15:04:26 +0100

On Fri, 26 Nov 2010 14:38:10 +0100
Christophe-Marie Duquesne <> wrote:

> Hi there,
> I wanted a menu that would allow me to select entries both from the
> uzbl history and from google suggest 'as you type' (like in firefox).
> While dmenu allows selecting entries in a static list (like uzbl
> history) easily, modifying this list and providing hints to google
> suggest did not seem to be possible. Since I did not see any other way
> to do that, I wrote a patch to dmenu. It adds 2 features:
> 1) if invoked with the option -s (-s for stream) dmenu will output
> selected entry on every keystroke (so you can feed a tool with the
> current entry).
> 2) in order to avoid waiting for the input stream to finish before
> allowing the user for select entries (and so that you can continue
> feeding it from stdin while you type), dmenu reads stdin in a thread.
> The idea is to feed dmenu with hints deduced from its stdout. As an
> example, here is how this can be used:
> #!/bin/bash
> socat UNIX-LISTEN:/tmp/dmenu_suggest - | dmenu -s | tee /tmp/results
> | \ while read line; do echo $line | ./google_suggest; done | \
> socat - UNIX-CONNECT:/tmp/dmenu_suggest
> tail -n1 /tmp/results && rm /tmp/results
> google_suggest is a python script I wrote. It reads search terms from
> stdin and outputs suggestions from google suggest API (I have attached
> it).
> If you are interested, you can pull my dmenu patch from
> Although the script above
> works correctly on my machine, the patch breaks dmenu in other
> situations. I would be interested if the persons who find this idea
> interesting would be kind enough to provide some constructive advices
> about the way to do that, e.g. if you see any cleaner method or if you
> have suggestions for doing that in a better way without patching
> dmenu. Advices like "don't do that" or "stop rewriting firefox" will
> probably not help.

Cool. I've been pondering this feature before.
Because if feeding dmenu stdin is time-consuming (i have some sorts
and whatnot when reading my "most often invoked entries") the delay
caused by dmenu waiting for stdin input to be complete is noticeable.

I would prefer if it works like this:
- when you invoke dmenu, it immediately appears, and user can start
typing input. as soon as dmenu is started, it starts reading stdin,
however fast or slow it goes until EOF.
- anytime anything happens (user changes his query or new line is
  read on stdin) the search results are updated in realtime accordingly.

I think the code/algorithms to realize this must be pretty complicated
for it to work nicely (high performance).. But your patches seem
trivial, so did I miss something?

Also, what do you do if the user types something, you feed google
suggest results to stdin, and then the user erases the line and types
something completely different? the old suggestions are still in
dmenu's datastructure so they can still appear in the search result?

And how exactly do you make sure the suggestions are shown for the
corresponding query? I would expect you would prefix the suggestions
with the query, but don't see anything like that in your python code.

Received on Fri Nov 26 2010 - 15:04:26 CET

This archive was generated by hypermail 2.2.0 : Fri Nov 26 2010 - 15:12:02 CET