On Wed, Aug 30, 2023 at 05:41:28PM +0100, Christopher Lang wrote:
> On Wed, Aug 30, 2023 at 05:48:13PM +0200, Страхиња Радић wrote:
> > On 23/08/30 09:43AM, Randy Palamar wrote:
> > > Personally I see little need for such a patch. I don't really
> > > think anyone is pressing <CTRL>+<RETURN> by mistake; they
> > > are nowhere near each other on most (all?) keyboard layouts.
> 
> A dmenu script in the dmenu repository should set the example for how to
> properly use dmenu. If dmenu_run has this (albiet small) bug, then it
> could make users assume dmenu always outputs a single line.
> 
> > > Actually I didn't even know about this feature despite using
> > > dmenu in a number of different scripts for many years. I'm
> > > already thinking of some use cases.
> 
> If users saw that dmenu_run was handling multi line output from dmenu,
> it could alert them to this feature.
> 
> > I would actually turn this patch the other way around--and have multiple 
> > selection execute all the selected commands.
> 
> This would be my implementation for executing all selected commands:
> 
> #!/bin/sh
> for x in $(dmenu_path | dmenu "$@"); do
>   echo "$x" | ${SHELL:-"/bin/sh"} &
> done
> 
> I suppose this behaviour is more intuitive, but it is a little more
> complicated. What are peoples preferences between original patch and
> executing all commands?
> 
> --
> Christopher
> 

Hi,

If it is a bug then I think it would make more sense to execute all current
output lines.

Currently when you CTRL-Enter on an entry the output will not directly flush.
For example you could type "st" and press CTRL-ENTER 3 times and press escape.
Then it would still open st 3 times:

It is safer to use printf instead of echo, because echo interprets escape
sequences.

Concept patch below:

diff --git a/dmenu.c b/dmenu.c
index 40f93e0..4839f47 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -490,6 +490,7 @@ insert:
        case XK_Return:
        case XK_KP_Enter:
                puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
+               fflush(stdout);
                if (!(ev->state & ControlMask)) {
                        cleanup();
                        exit(0);
diff --git a/dmenu_run b/dmenu_run
index 834ede5..73d77ec 100755
--- a/dmenu_run
+++ b/dmenu_run
@@ -1,2 +1,4 @@
 #!/bin/sh
-dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &
+dmenu_path | dmenu "$@" | while read -r line; do
+       printf '%s' "${line}" | ${SHELL:-"/bin/sh"} &
+done

-- 
Kind regards,
Hiltjo

Reply via email to