Code Monkey home page Code Monkey logo

Comments (2)

cassie-is-asleep avatar cassie-is-asleep commented on September 28, 2024

In the meantime, here's a quick POSIX sh script that does such a fix externally, allowing you to quickly test the impact such a change would have.

#!/bin/sh
printf 'exec %s\n' "$(j4-dmenu-desktop --no-exec "$@")" | ${SHELL:-sh} &

from j4-dmenu-desktop.

meator avatar meator commented on September 28, 2024

This is a interesting problem. J4dd executes the programs with <shell> -c <command_string>. Some shells (like bash) automatically exec the last component of the command string (in most cases the command string has only one component in j4dd so the program is always execed). But some shells don't do that (like dash).

I think this is why no one (including me) has discovered this issue.

I've incorporated a fix into my PR #132. I would recommend You to compile and use the PR's version of j4dd because it contains many fixes and new features.

If don't want to use my version of j4dd you can apply this patch to j4dd:

--- a/src/Main.hh
+++ b/src/Main.hh
@@ -260,7 +260,9 @@ private:
         }
 
         this->dmenu->display();
-        std::string command = get_command();
+        std::string command;
+        bool iscustom;
+        std::tie(command, iscustom) = get_command();
         if (this->wrapper.length())
             command = this->wrapper+" \""+command+"\"";
         delete this->dmenu;
@@ -273,6 +275,8 @@ private:
             static const char *shell = 0;
             if((shell = getenv("SHELL")) == 0)
                 shell = "/bin/sh";
+            if (!iscustom)
+                command = "exec " + command;
 
             fprintf(stderr, "%s -c '%s'\n", shell, command.c_str());
 
@@ -317,7 +321,7 @@ private:
         return 0;
     }
 
-    std::string get_command() {
+    std::pair<std::string, bool> get_command() {
         std::string choice;
         std::string args;
         Application *app;
@@ -326,13 +330,13 @@ private:
 
         choice = dmenu->read_choice(); // Blocks
         if(choice.empty())
-            return "";
+            return std::make_pair("", false);
 
         fprintf(stderr, "User input is: %s %s\n", choice.c_str(), args.c_str());
 
         std::tie(app, args) = apps.search(choice, exclude_generic);
         if (!app) {
-            return args;
+            return std::make_pair(args, true);
         }
 
         if(usage_log) {
@@ -346,7 +350,7 @@ private:
         }
 
         ApplicationRunner app_runner(terminal, *app, args);
-        return app_runner.command();
+        return std::make_pair(app_runner.command(), false);
     }
 
 private:

My code (both the patch and the fdb58ae commit in #132) only prepends "exec " to programs which have a desktop file. I don't know if You knew this (it isn't documented anywhere as far as I know and I discovered it only after thoroughly reading the code) but when a command that doesn't match any desktop entry is entered, j4dd tries to execute it directly. Because You can provide custom commands to j4dd, prepending "exec " to them might produce unexpected results.

from j4-dmenu-desktop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.