You are not logged in.

#1 Today 09:49:57

unfixable
Member
From: internet
Registered: Today
Posts: 2
Website

Problem with passing arguments when using a list of programs in dmenu

I am using i3-wm with dmenu, and I want dmenu to display only the list of programs I need, not all programs it finds in environment variables, while still keeping the ability to call an arbitrary command from dmenu.

This can be done by passing dmenu an arbitrary list of names, for example like this:

dmenu < ~/.dmenu_names

After entering the required command, dmenu returns the input as a string, which you can then call in any way you like (e.g., using sh -c, etc.) or pass it somewhere else.

In my case, I use an i3-wm bind that looks like this:

bindsym Mod4+d exec --no-startup-id $(dmenu < ~/.dmenu_names)

Problem:

If you call dmenu through the bind, all space-separated arguments are passed as separate ones, even if they are enclosed in quotes. For example:

command arg1 "arg 2"

will result in three arguments: "arg1", "arg", "2".

However, if you call dmenu through the terminal, the argument passing behavior will be normal:

$(dmenu < ~/.dmenu_names) arg1 "arg 2"

will get 2 arguments: "arg1" and "arg 2".

At the same time, all this manual command invocation can be avoided by using dmenu_run (from the same package), which is designed for directly running commands, but it doesn't support passing arbitrary lists of names - it only works with environment variables.
On the other hand, dmenu works with lists but returns only a string as a result.
When using dmenu_run, no issues with correct argument passing are observed.

So, how can I achieve the normal behavior of arguments, as when calling from the terminal or using dmenu_run?

Last edited by unfixable (Today 09:51:13)


i use arch btw

Offline

#2 Today 11:05:55

marcoe
Member
Registered: 2025-08-30
Posts: 11

Re: Problem with passing arguments when using a list of programs in dmenu

You have to make sure that the shell is responsible for splitting/quoting the arguments and running the command you pick in dmenu. The dmenu_run script is simply:

#!/bin/sh
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

If the behavior of the above is what you are after, then you can create your own script, call it my_dmenu_run:

#!/bin/sh
dmenu < ~/.dmenu_names | ${SHELL:-"/bin/sh"} &

And now anything you enter in this dmenu will be passed for the shell to interpret, then in your i3 configuration file:

bindsym Mod4+d exec --no-startup-id my_dmenu_run

Tested the above on sway.

Offline

#3 Today 11:25:40

unfixable
Member
From: internet
Registered: Today
Posts: 2
Website

Re: Problem with passing arguments when using a list of programs in dmenu

marcoe wrote:

You have to make sure that the shell is responsible for splitting/quoting the arguments and running the command you pick in dmenu. The dmenu_run script is simply:

#!/bin/sh
dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

If the behavior of the above is what you are after, then you can create your own script, call it my_dmenu_run:

#!/bin/sh
dmenu < ~/.dmenu_names | ${SHELL:-"/bin/sh"} &

And now anything you enter in this dmenu will be passed for the shell to interpret, then in your i3 configuration file:

bindsym Mod4+d exec --no-startup-id my_dmenu_run

Tested the above on sway.

Everything works just as I was trying to do originally! Thank you very much for your help!


i use arch btw

Offline

Board footer

Powered by FluxBB