This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit afb7ce1b55ed3b07f18ffcc3c7801877c8a7545d
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Wed Feb 26 19:00:54 2025 +0000

    run exec in desktop files and run exes/sh's directly on file-run
---
 src/efm/efm_back_end.c | 74 ++++++++++++++++++++++++++++++++++++++++----------
 src/efm/efm_util.c     | 62 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 119 insertions(+), 17 deletions(-)

diff --git a/src/efm/efm_back_end.c b/src/efm/efm_back_end.c
index ee59c5d..5faec7e 100644
--- a/src/efm/efm_back_end.c
+++ b/src/efm/efm_back_end.c
@@ -1,6 +1,7 @@
 #include "cmd.h"
 #include "efm_structs.h"
 #include "efreet_desktop.h"
+#include "eina_log.h"
 #include "sort.h"
 #include "efm.h"
 #include "efm_util.h"
@@ -420,7 +421,7 @@ static void
 _file_run(Smart_Data *sd EINA_UNUSED, Efreet_Desktop *d, Eina_List *files)
 {
   Eina_List *cmds = NULL;
-  char *cmd;
+  char      *cmd;
 
   efreet_desktop_command_get(d, files, _file_run_command_get, &cmds);
   if (d->terminal)
@@ -428,10 +429,44 @@ _file_run(Smart_Data *sd EINA_UNUSED, Efreet_Desktop *d, Eina_List *files)
       // XXX: handle run in terminal
     }
   EINA_LIST_FREE(cmds, cmd)
-    {
-      ecore_exe_run(cmd, NULL);
-      free(cmd);
-    }
+  {
+    ecore_exe_run(cmd, NULL);
+    free(cmd);
+  }
+}
+
+static void
+_file_desktop_run(Smart_Data *sd EINA_UNUSED, Eina_List *files)
+{
+  Eina_List  *l;
+  const char *file;
+
+  EINA_LIST_FOREACH(files, l, file)
+  {
+    Efreet_Desktop *d = efreet_desktop_new(file);
+
+    if (d)
+      {
+        printf("[DESKTOP] [%s]\n", file);
+        // the below basically does the below
+        // ecore_exe_run(file, NULL);
+        efreet_desktop_exec(d, NULL, NULL);
+        efreet_desktop_unref(d);
+      }
+  }
+}
+
+static void
+_file_execute_run(Smart_Data *sd EINA_UNUSED, Eina_List *files)
+{
+  Eina_List  *l;
+  const char *file;
+
+  EINA_LIST_FOREACH(files, l, file)
+  {
+    printf("[EXEC] [%s]\n", file);
+    ecore_exe_run(file, NULL);
+  }
 }
 
 void
@@ -669,23 +704,32 @@ _cb_thread_notify(void *data, Ecore_Thread *th EINA_UNUSED, void *msg)
         }
         KEY_WALK_END
 
-        if (open_with_desktop) d = efreet_desktop_new(open_with_desktop);
+        if (open_with_desktop)
+          {
+            if (!strcmp(open_with_desktop, "..DESKTOP.."))
+              { // run the .de3sktop file Exec line
+                _file_desktop_run(sd, files);
+              }
+            else if (!strcmp(open_with_desktop, "..EXECUTE.."))
+              { // execute the file itself
+                _file_execute_run(sd, files);
+              }
+            else
+              {
+                d = efreet_desktop_new(open_with_desktop);
+              }
+          }
         if (d)
           {
             _file_run(sd, d, files);
             efreet_desktop_unref(d);
           }
+        else
+          { // XXX: pop up dialog to ask what to open with...
+        
+          }
         EINA_LIST_FREE(files, file)
         {
-          if (d)
-            {
-              fprintf(stderr, "FRONT OPEN: [%s] [%s]\n", open_with_desktop,
-                      file);
-            }
-          else
-            {
-              fprintf(stderr, "FRONT OPEN: [%s]\n", file);
-            }
           eina_stringshare_del(file);
         }
         CMD_DONE;
diff --git a/src/efm/efm_util.c b/src/efm/efm_util.c
index d2d2a19..f2ab3b1 100644
--- a/src/efm/efm_util.c
+++ b/src/efm/efm_util.c
@@ -735,6 +735,44 @@ _icon_path_cmd_strbuf_append(Eina_Strbuf *strbuf, const char *key,
   eina_strbuf_free(buf);
 }
 
+static Eina_Bool
+_file_direct_run_get(Icon *icon)
+{
+  if ((!icon->info.dir) && (!icon->info.special))
+    { // not dir or special node
+      const char *f = cmd_key_find(icon->cmd, "mode");
+
+      if (f)
+        { // get mode strig hex and chexck execute bits
+          int mode = strtoull(f, NULL, 16);
+
+          if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) return EINA_TRUE;
+        }
+    }
+  return EINA_FALSE;
+}
+
+static Eina_Bool
+_file_desktop_exec_get(Icon *icon)
+{
+  Eina_Bool ret = EINA_FALSE;
+
+  if (!strcmp(icon->info.mime, "application/x-desktop"))
+    {
+      char buf[PATH_MAX];
+      Efreet_Desktop *d;
+
+      snprintf(buf, sizeof(buf), "%s%s", icon->sd->config.path, icon->info.file);
+      d = efreet_desktop_new(buf);
+      if (d)
+        {
+          if ((d->exec) && (d->exec[0])) ret = EINA_TRUE;
+          efreet_desktop_unref(d);
+        }
+    }
+  return ret;
+}
+
 void
 _icon_open_with_cmd_strbuf_append(Eina_Strbuf *strbuf, const char *key,
                                   Smart_Data *sd)
@@ -752,7 +790,27 @@ _icon_open_with_cmd_strbuf_append(Eina_Strbuf *strbuf, const char *key,
       // FIXME: for now just pick the first found and use its mime. later
       // let's use the most common mme type instead amongst all selected
       // files
-      if (!icon->info.mime) continue;
+      if ((!icon->info.mime)
+          || (!strcmp(icon->info.mime, "application/x-executable"))
+          || (!strcmp(icon->info.mime, "application/x-shellscript")))
+        {
+          if (_file_direct_run_get(icon))
+            {
+              // tell whoever is opening to direct execute
+              cmd_strbuf_append(strbuf, key, "..EXECUTE..");
+              printf("FFF: direct exec [%s] [%s]\n", icon->info.file,
+                     icon->info.mime);
+              return;
+            }
+          continue;
+        }
+      if (_file_desktop_exec_get(icon))
+        {
+          cmd_strbuf_append(strbuf, key, "..DESKTOP..");
+          printf("FFF: [%s]: desktop [%s]\n", icon->info.file, icon->info.mime);
+          return;
+        }
+      printf("FFF: [%s]: [%s]\n", icon->info.file, icon->info.mime);
       Efreet_Desktop *d = _mimeapps_handler_find(icon->info.mime);
       if (!d) continue;
       // open-with=/path/to/file.desktop
@@ -2482,4 +2540,4 @@ _cb_reblock(void *data)
   // needed etc.
   sd->reblocked = EINA_TRUE;
   evas_object_smart_changed(sd->o_smart);
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to