Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to escape the command correctly for dmenu #116

Open
tleydxdy opened this issue Feb 18, 2021 · 3 comments
Open

unable to escape the command correctly for dmenu #116

tleydxdy opened this issue Feb 18, 2021 · 3 comments

Comments

@tleydxdy
Copy link

I'm running into the same problem as #68 , except I wasn't trying to hard code any colors. I want to create a script similar to dmenu_run which gets passed whatever command dmenu expects and it does the right thing. my initial attempt looks like this:

#!/bin/sh
exec /usr/bin/j4-dmenu-desktop --dmenu="dmenu $@" --usage-log="$HOME/.cache/desktop_run"

This causes problem since the line is executed by a shell which treats "#" as a comment. I tried some ways to escape it but without success. what should I do here? imo, using a shell to parse --dmenu= is too strong, since the user is probably invoking the command with a shell already so any parsing can be done beforehand.

@tleydxdy
Copy link
Author

My suggestion would be to change to take arguments like this

j4-dmenu-desktop -a -b -c --long-arg1 --long-arg2 -- dmenu -dmenu-arg1 -dmenu-arg2 -dmenu-arg3

i.e. after -- is the dmenu command that will be used.
This way the program can just directly exec the rest of the argv after -- and don't need to invoke the shell or do any parsing.

@enkore
Copy link
Owner

enkore commented Feb 21, 2021

I see. Sort of a perfect-forwarding problem, not very elegant to solve, but possible.

#!/bin/sh
quoted=""
for arg in "$@"
do
    quoted="$quoted $(set | grep '^arg=' | cut -d= -f2)"
done

j4-dmenu-desktop --dmenu="dmenu $quoted"

@tleydxdy
Copy link
Author

tleydxdy commented Feb 23, 2021

After much digging, I found this feature of bash (which means i need to use bash :\). it solves my exact problem, but obviously doesn't scale well to other escaping problems.

--dmenu="dmenu ${*//#/\\#}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants