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 4e1f9d11a46087e4d166bb6f535d5041fd6ed2b6
Author: Carsten Haitzler (Rasterman) <[email protected]>
AuthorDate: Mon Mar 30 11:41:37 2026 +0100
fs backend - move typebuf to its own file
getting big enough to live on its own
---
src/backends/default/meson.build | 1 +
src/backends/default/open.c | 440 +--------------------------------------
src/backends/default/open.h | 30 +++
src/backends/default/typebuf.c | 403 +++++++++++++++++++++++++++++++++++
src/backends/default/typebuf.h | 8 +
5 files changed, 453 insertions(+), 429 deletions(-)
diff --git a/src/backends/default/meson.build b/src/backends/default/meson.build
index fdc4a58..6bd0af2 100644
--- a/src/backends/default/meson.build
+++ b/src/backends/default/meson.build
@@ -17,6 +17,7 @@ executable('open', [
'icon_override.c',
'fs.c',
'status.c',
+ 'typebuf.c',
],
include_directories: inc,
dependencies: deps,
diff --git a/src/backends/default/open.c b/src/backends/default/open.c
index b37c2dc..8f0415c 100644
--- a/src/backends/default/open.c
+++ b/src/backends/default/open.c
@@ -6,26 +6,7 @@
// the front end that consumes the output of this should do NO file access
// itself at all and do everything via fs handlers for open, delete, rename
// copy, import, export etc.
-#include <Eina.h>
-#include <Ecore.h>
-#include <Ecore_File.h>
-#include <Efreet.h>
-#include <Efreet_Mime.h>
-#include <Eet.h>
-
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-
-#include "cmd.h"
-#include "sha.h"
-#include "meta.h"
-#include "icon_override.h"
-#include "thumb_check.h"
-#include "esc.h"
-#include "util.h"
-#include "fs.h"
-#include "status.h"
+#include "open.h"
typedef struct
{
@@ -71,7 +52,8 @@ typedef struct
Eina_Bool repeat : 1;
} Sub_Timer;
-static Ecore_File_Monitor *mon = NULL;
+Ecore_File_Monitor *mon = NULL;
+
static const char *icon_theme = NULL;
static const char *config_dir = NULL;
static const char *data_dir = NULL;
@@ -752,16 +734,6 @@ _file_add_mod_meta_icon_append(const char *path, const char *meta,
eina_stringshare_del(s);
}
-static void
-_cmd_typebuf_icon_send(const char *icon)
-{
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-icon");
-
- if (!strbuf) return;
- cmd_strbuf_append(strbuf, "icon", icon);
- cmd_strbuf_print_consume(strbuf);
-}
-
static const char *
_file_add_path_icon_override_find(const char *path, const char *field)
{
@@ -1330,8 +1302,8 @@ done:
return res;
}
-static void
-_op_run(const char *op, Eina_List *files, const char *dst)
+void
+op_run(const char *op, Eina_List *files, const char *dst)
{
Eina_Strbuf *buf;
const char *s;
@@ -1416,15 +1388,15 @@ _handle_drop_paste(const char *over, const char *over_position, const char *acti
{
if ((!action) || (!strcmp(action, "copy")))
{
- _op_run("cp", files, mondir);
+ op_run("cp", files, mondir);
}
else if (!strcmp(action, "move"))
{
- _op_run("mv", files, mondir);
+ op_run("mv", files, mondir);
}
else if (!strcmp(action, "link"))
{
- _op_run("ln", files, mondir);
+ op_run("ln", files, mondir);
}
else // "ask", "list", "description", or anything else
{ // actully we should never get this
@@ -1438,114 +1410,6 @@ _meta_update(const char *path)
_file_mod(path);
}
-static char *
-_path_arg_rel_to_abs(const char *arg)
-{
- Eina_Strbuf *buf = eina_strbuf_new();
- const char *mondir = ecore_file_monitor_path_get(mon);
- const char *s;
- char *ret = NULL;
-
- if (!buf) return NULL;
- if (!mondir) goto done;
- if (!strncmp(arg, "../", 3))
- { // ../relatve/path.xx
- char *tmps = ecore_file_dir_get(mondir);
-
- if (tmps)
- {
- eina_strbuf_append_printf(buf, "%s/%s", tmps, arg + 3);
- free(tmps);
- }
- }
- else if (arg[0] == '/')
- { // /full/path/arg.xx
- eina_strbuf_append(buf, arg);
- }
- else
- { // flename/path/blah.xx
- const char *append = arg;
-
- if (!strncmp(arg, "./", 2)) append += 2;
- eina_strbuf_append_printf(buf, "%s/%s", mondir, append);
- }
- s = eina_strbuf_string_get(buf);
- if (s) ret = strdup(s);
-done:
- eina_strbuf_free(buf);
- return ret;
-}
-
-static void
-_typebuf_cd(const char *dest)
-{
- Eina_Strbuf *strbuf = cmd_strbuf_new("dir-request");
- Eina_Strbuf *strbuf2 = NULL;
- const char *mondir = ecore_file_monitor_path_get(mon);
- char *path;
-
- if (!strbuf) return;
- if ((!mondir) || (!dest) || (!dest[0])) goto done;
- strbuf2 = eina_strbuf_new();
- if (!strbuf2) goto done;
- if (dest[0] != '/') eina_strbuf_append_printf(strbuf2, "%s/%s", mondir, dest);
- else eina_strbuf_append(strbuf2, dest);
- fprintf(stderr, "XXX: GO TO [%s]\n", eina_strbuf_string_get(strbuf2));
- path = ecore_file_realpath(eina_strbuf_string_get(strbuf2));
- eina_strbuf_free(strbuf2);
- if (path)
- {
- cmd_strbuf_append(strbuf, "path", path);
- cmd_strbuf_print_consume(strbuf);
- free(path);
- return;
- }
-done:
- eina_strbuf_free(strbuf);
-}
-
-static char *
-_complete_arg_path(char *arg)
-{
- char *comp = NULL;
- char *full = _path_arg_rel_to_abs(arg);
-
- if (!full) return NULL;
- comp = util_complete(full, COMPLETE_ANY);
- free(full);
- return comp;
-}
-
-static Eina_Bool
-_complete_last_arg_path_cmd(char **args, Eina_Strbuf *cmd, const char *cmd_arg)
-{
- Eina_Strbuf *buf = eina_strbuf_new();
- Eina_Bool ret = EINA_FALSE;
- int i;
-
- if (!buf) return ret;
- for (i = 0; args[i]; i++)
- {
- if (args[i + 1]) // other args - just append them
- eina_strbuf_append_printf(buf, "%s ", args[i]);
- else
- { // last arg
- char *comp = _complete_arg_path(args[i]);
-
- if (comp)
- {
- eina_strbuf_append_printf(buf, "%s ", comp);
- free(comp);
- ret = EINA_TRUE;
- }
- else eina_strbuf_append(buf, args[i]);
- }
- }
- cmd_strbuf_append(cmd, cmd_arg, eina_strbuf_string_get(buf));
- eina_strbuf_free(buf);
- return ret;
-}
-
void
do_handle_cmd(Cmd *c)
{
@@ -1742,7 +1606,7 @@ do_handle_cmd(Cmd *c)
KEY_WALK_END
if (files)
{
- _op_run("rm", files, NULL);
+ op_run("rm", files, NULL);
EINA_LIST_FREE(files, s) eina_stringshare_del(s);
}
}
@@ -1761,7 +1625,7 @@ do_handle_cmd(Cmd *c)
KEY_WALK_END
if (files)
{
- _op_run("trash", files, NULL);
+ op_run("trash", files, NULL);
EINA_LIST_FREE(files, s) eina_stringshare_del(s);
}
}
@@ -1833,288 +1697,7 @@ do_handle_cmd(Cmd *c)
EINA_LIST_FREE(files, s) eina_stringshare_del(s);
}
}
- else if (!strcmp(c->command, "typebuf"))
- {
- char **args = NULL;
- const char *op = cmd_key_find(c, "op"); // "update", "complete", "run", "cursor"
- const char *line_str = cmd_key_find(c, "line");
-// dont need this atm.
-// const char *cpos_str = cmd_key_find(c, "cursor-pos");
-// int cpos = -1;
-// if (cpos_str) cpos = atoi(cpos_str);
- if (line_str) args = eina_str_split(line_str, " ", -1);
- if (args)
- {
- if (!strcmp(args[0], "ls"))
- { // built-in cmd: ls [file1]
- _cmd_typebuf_icon_send("std:view-refresh");
- if ((op) && (!strcmp(op, "run")))
- { // only support 1 arg (first) if there - "cd arg"
- if ((args[1]) && (args[1][0])) _typebuf_cd(args[1]);
- else
- {
- Eina_Strbuf *strbuf = cmd_strbuf_new("view-refresh");
- cmd_strbuf_print_consume(strbuf);
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- { // only support 1 arg (first) if there - "cd arg"
- if ((args[1]) && (args[1][0]))
- { // we have 1 or more args - assume 1 and its a file/path
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf, "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- }
- else if (!strcmp(args[0], "rm"))
- { // built-in cmd: rm [-f] file1 [file2] [file3] ...
- _cmd_typebuf_icon_send("std:edit-delete");
- if ((op) && (!strcmp(op, "run")))
- {
- if ((args[1]) && (args[1][0]))
- {
- Eina_List *files = NULL;
- int i, j;
- Eina_Bool opt_f = EINA_FALSE;
- char *full = NULL;
-
- for (i = 1; args[i]; i++)
- {
- const char *arg = args[i];
-
- if (arg[0] == '-')
- { // its an option
- for (j = 1; arg[j]; j++)
- {
- if (arg[j] == 'f') opt_f = EINA_TRUE;
- // ignore other: we're fuzzy not 100% compat
- }
- }
- else if (arg[0])
- { // it's a file - convert to path if needed
- full = _path_arg_rel_to_abs(arg);
- if (full) files = eina_list_append(files, full);
- }
- }
- if (files)
- { // only run if we have files
- if (opt_f) _op_run("rm", files, NULL);
- else _op_run("trash", files, NULL);
- EINA_LIST_FREE(files, full) free(full);
- }
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- {
- if ((args[1]) && (args[1][0]))
- { // we have 1 or more args - complete last
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf, "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- }
- else if (!strcmp(args[0], "unlink"))
- { // built-in cmd: unlink file1 [file2] [file3] ...
- _cmd_typebuf_icon_send("std:edit-delete");
- if ((op) && (!strcmp(op, "run")))
- {
- if ((args[1]) && (args[1][0]))
- {
- Eina_List *files = NULL;
- int i;
- char *full = NULL;
-
- for (i = 1; args[i]; i++)
- {
- const char *arg = args[i];
-
- if (arg[0])
- { // it's a file - convert to path if needed
- full = _path_arg_rel_to_abs(arg);
- if (full) files = eina_list_append(files, full);
- }
- }
- if (files)
- { // only run if we have files
- _op_run("rm", files, NULL);
- EINA_LIST_FREE(files, full) free(full);
- }
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- {
- if ((args[1]) && (args[1][0]))
- { // we have 1 or more args - complete last
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf, "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- }
- else if (!strcmp(args[0], "mv"))
- { // built-in cmd: mv file1 [file2] [file3] [destdir] ...
- // built-in cmd: mv file newfilename
- // at least 2 args. last arg is dest dir OR new filename
- _cmd_typebuf_icon_send("std:edit-rename");
-// _op_run("mv", files, NULL);
- }
- else if (!strcmp(args[0], "cp"))
- { // built-in cmd: cp file1 [file2] [file3] [destdir] ...
- // built-in cmd: cp file copyfilename
- // at least 2 args. last arg is dest dir OR new copy filename
- _cmd_typebuf_icon_send("std:edit-copy");
-// _op_run("cp", files, NULL);
- }
- else if (!strcmp(args[0], "ln"))
- { // built-in cmd: ln [-s] dest linkfilename
- _cmd_typebuf_icon_send("std:insert-link");
- if ((op) && (!strcmp(op, "run")))
- { // must have 2 args minimum
- if ((args[1]) && (args[1][0]) && (args[2]) && (args[2][0]))
- {
- Eina_List *files = NULL;
- int i;
- char *full = NULL;
-
- for (i = 1; args[i]; i++)
- {
- const char *arg = args[i];
-
- if (arg[0] == '-')
- { // its an option - ignore it - we ALWAYS do -s
- }
- else if (arg[0])
- { // it's a file - convert to path if needed
- if (!files) full = strdup(arg);
- else full = _path_arg_rel_to_abs(arg);
- if (full) files = eina_list_append(files, full);
- }
- }
- if (files)
- { // only run if we have files
- char *link_src = eina_list_nth(files, 0);
- const char *link_file = eina_list_nth(files, 1);
- if (link_src && link_file)
- {
- status_begin();
- status_op("ln");
- fs_ln(link_src, link_file, EINA_FALSE);
- status_end();
- }
- EINA_LIST_FREE(files, full) free(full);
- }
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- { // complete last arg
- if ((args[1]) && (args[1][0]))
- { // we have 1 or more args
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf, "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- }
- else if (!strcmp(args[0], "cd"))
- { // built-in cmd: cd dirname
- _cmd_typebuf_icon_send("std:folder");
- if ((op) && (!strcmp(op, "run")))
- { // only support 1 arg (first) if there - "cd arg"
- if ((args[1]) && (args[1][0])) _typebuf_cd(args[1]);
- else
- { // no arg - go to $HOME
- const char *home = getenv("HOME");
- if (home) _typebuf_cd(home);
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- { // complete last arg
- if ((args[1]) && (args[1][0]))
- { // we have 1 or more args
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf, "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- }
- else if (args[0])
- { // generic typebuf matches a desktop file for an app/command you
- // have installed and indexed - thus can be extended with more
- // installed desktop files that are found/indexed
- // first try - match by the exec command in the desktop
- Efreet_Desktop *d = efreet_util_desktop_exec_find(args[0]);
-
- if (!d) // that didn't work
- { // can't find by exec - let's find by desktop filename/oid
- char buf[1024];
-
- snprintf(buf, sizeof(buf), "%s.desktop", args[0]);
- d = efreet_util_desktop_file_id_find(buf);
- }
- // if that didn't work find by name field in desktop
- if (!d) d = efreet_util_desktop_name_find(args[0]);
- if (d)
- { // found some desktop matching the cmd
- Eina_Strbuf *buf2 = eina_strbuf_new();
-
- if (buf2)
- { // provide the icon from the desktop file for typebuf
- eina_strbuf_append_printf(buf2, "std:%s", d->icon);
- _cmd_typebuf_icon_send(eina_strbuf_string_get(buf2));
- eina_strbuf_free(buf2);
- }
- if ((op) && (!strcmp(op, "run")))
- { // ask front end to "run" files provided as args
- Eina_Strbuf *strbuf = cmd_strbuf_new("file-run");
-
- if (strbuf)
- {
- int i;
- const char *mondir = ecore_file_monitor_path_get(mon);
-
- if (mondir)
- { // cwd is this dir for cmds as if we were in a terminal in cwd
- cmd_strbuf_append(strbuf, "cwd", mondir);
- cmd_strbuf_append(strbuf, "open-with",
- d->orig_path);
- // add args as files
- for (i = 1; args[i]; i++)
- {
- if ((args[i]) && (args[i][0]))
- cmd_strbuf_append(strbuf, "path",args[i]);
- }
- // send file-run cmd back to front end
- cmd_strbuf_print_consume(strbuf);
- }
- }
- }
- else if ((op) && (!strcmp(op, "complete")))
- { // complete last arg as file
- if ((args[1]) && (args[1][0]))
- {
- Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
- if (_complete_last_arg_path_cmd(args, strbuf,
- "string"))
- cmd_strbuf_print_consume(strbuf);
- else eina_strbuf_free(strbuf);
- }
- }
- efreet_desktop_free(d);
- }
- }
-// for (p = args; *p != NULL; p++)
-// fprintf(stderr, "XXX:ZZZ: [%s]\n", *p);
- }
- free(*args);
- free(args);
- }
+ else if (!strcmp(c->command, "typebuf")) typebuf_cmd(c);
// cmd_dump_sterr(c);
}
@@ -2186,4 +1769,3 @@ do_shutdown(void)
efreet_shutdown();
ecore_file_shutdown();
}
-;
diff --git a/src/backends/default/open.h b/src/backends/default/open.h
new file mode 100644
index 0000000..eee4fcf
--- /dev/null
+++ b/src/backends/default/open.h
@@ -0,0 +1,30 @@
+#ifndef OPEN_H
+# define OPEN_H
+
+# include <Eina.h>
+# include <Ecore.h>
+# include <Ecore_File.h>
+# include <Efreet.h>
+# include <Efreet_Mime.h>
+# include <Eet.h>
+
+# include <sys/types.h>
+# include <pwd.h>
+# include <grp.h>
+
+# include "cmd.h"
+# include "sha.h"
+# include "meta.h"
+# include "icon_override.h"
+# include "thumb_check.h"
+# include "esc.h"
+# include "util.h"
+# include "fs.h"
+# include "status.h"
+# include "typebuf.h"
+
+extern Ecore_File_Monitor *mon;
+
+void op_run(const char *op, Eina_List *files, const char *dst);
+
+#endif
\ No newline at end of file
diff --git a/src/backends/default/typebuf.c b/src/backends/default/typebuf.c
new file mode 100644
index 0000000..ccee411
--- /dev/null
+++ b/src/backends/default/typebuf.c
@@ -0,0 +1,403 @@
+#include "open.h"
+
+static void
+_cmd_typebuf_icon_send(const char *icon)
+{
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-icon");
+
+ if (!strbuf) return;
+ cmd_strbuf_append(strbuf, "icon", icon);
+ cmd_strbuf_print_consume(strbuf);
+}
+
+static void
+_typebuf_cd(const char *dest)
+{
+ Eina_Strbuf *strbuf = cmd_strbuf_new("dir-request");
+ Eina_Strbuf *strbuf2 = NULL;
+ const char *mondir = ecore_file_monitor_path_get(mon);
+ char *path;
+
+ if (!strbuf) return;
+ if ((!mondir) || (!dest) || (!dest[0])) goto done;
+ strbuf2 = eina_strbuf_new();
+ if (!strbuf2) goto done;
+ if (dest[0] != '/') eina_strbuf_append_printf(strbuf2, "%s/%s", mondir, dest);
+ else eina_strbuf_append(strbuf2, dest);
+ fprintf(stderr, "XXX: GO TO [%s]\n", eina_strbuf_string_get(strbuf2));
+ path = ecore_file_realpath(eina_strbuf_string_get(strbuf2));
+ eina_strbuf_free(strbuf2);
+ if (path)
+ {
+ cmd_strbuf_append(strbuf, "path", path);
+ cmd_strbuf_print_consume(strbuf);
+ free(path);
+ return;
+ }
+done:
+ eina_strbuf_free(strbuf);
+}
+
+static char *
+_path_arg_rel_to_abs(const char *arg)
+{
+ Eina_Strbuf *buf = eina_strbuf_new();
+ const char *mondir = ecore_file_monitor_path_get(mon);
+ const char *s;
+ char *ret = NULL;
+
+ if (!buf) return NULL;
+ if (!mondir) goto done;
+ if (!strncmp(arg, "../", 3))
+ { // ../relatve/path.xx
+ char *tmps = ecore_file_dir_get(mondir);
+
+ if (tmps)
+ {
+ eina_strbuf_append_printf(buf, "%s/%s", tmps, arg + 3);
+ free(tmps);
+ }
+ }
+ else if (arg[0] == '/')
+ { // /full/path/arg.xx
+ eina_strbuf_append(buf, arg);
+ }
+ else
+ { // flename/path/blah.xx
+ const char *append = arg;
+
+ if (!strncmp(arg, "./", 2)) append += 2;
+ eina_strbuf_append_printf(buf, "%s/%s", mondir, append);
+ }
+ s = eina_strbuf_string_get(buf);
+ if (s) ret = strdup(s);
+done:
+ eina_strbuf_free(buf);
+ return ret;
+}
+
+static char *
+_complete_arg_path(char *arg)
+{
+ char *comp = NULL;
+ char *full = _path_arg_rel_to_abs(arg);
+
+ if (!full) return NULL;
+ comp = util_complete(full, COMPLETE_ANY);
+ free(full);
+ return comp;
+}
+
+static Eina_Bool
+_complete_last_arg_path_cmd(char **args, Eina_Strbuf *cmd, const char *cmd_arg)
+{
+ Eina_Strbuf *buf = eina_strbuf_new();
+ Eina_Bool ret = EINA_FALSE;
+ int i;
+
+ if (!buf) return ret;
+ for (i = 0; args[i]; i++)
+ {
+ if (args[i + 1]) // other args - just append them
+ eina_strbuf_append_printf(buf, "%s ", args[i]);
+ else
+ { // last arg
+ char *comp = _complete_arg_path(args[i]);
+
+ if (comp)
+ {
+ eina_strbuf_append_printf(buf, "%s ", comp);
+ free(comp);
+ ret = EINA_TRUE;
+ }
+ else eina_strbuf_append(buf, args[i]);
+ }
+ }
+ cmd_strbuf_append(cmd, cmd_arg, eina_strbuf_string_get(buf));
+ eina_strbuf_free(buf);
+ return ret;
+}
+
+void
+typebuf_cmd(Cmd *c)
+{
+ char **args = NULL;
+ const char *op
+ = cmd_key_find(c, "op"); // "update", "complete", "run", "cursor"
+ const char *line_str = cmd_key_find(c, "line");
+ // dont need this atm.
+ // const char *cpos_str = cmd_key_find(c, "cursor-pos");
+ // int cpos = -1;
+ // if (cpos_str) cpos = atoi(cpos_str);
+ if (line_str) args = eina_str_split(line_str, " ", -1);
+ if (args)
+ {
+ if (!strcmp(args[0], "ls"))
+ { // built-in cmd: ls [file1]
+ _cmd_typebuf_icon_send("std:view-refresh");
+ if ((op) && (!strcmp(op, "run")))
+ { // only support 1 arg (first) if there - "cd arg"
+ if ((args[1]) && (args[1][0])) _typebuf_cd(args[1]);
+ else
+ {
+ Eina_Strbuf *strbuf = cmd_strbuf_new("view-refresh");
+ cmd_strbuf_print_consume(strbuf);
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ { // only support 1 arg (first) if there - "cd arg"
+ if ((args[1]) && (args[1][0]))
+ { // we have 1 or more args - assume 1 and its a file/path
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ }
+ else if (!strcmp(args[0], "rm"))
+ { // built-in cmd: rm [-f] file1 [file2] [file3] ...
+ _cmd_typebuf_icon_send("std:edit-delete");
+ if ((op) && (!strcmp(op, "run")))
+ {
+ if ((args[1]) && (args[1][0]))
+ {
+ Eina_List *files = NULL;
+ int i, j;
+ Eina_Bool opt_f = EINA_FALSE;
+ char *full = NULL;
+
+ for (i = 1; args[i]; i++)
+ {
+ const char *arg = args[i];
+
+ if (arg[0] == '-')
+ { // its an option
+ for (j = 1; arg[j]; j++)
+ {
+ if (arg[j] == 'f') opt_f = EINA_TRUE;
+ // ignore other: we're fuzzy not 100% compat
+ }
+ }
+ else if (arg[0])
+ { // it's a file - convert to path if needed
+ full = _path_arg_rel_to_abs(arg);
+ if (full) files = eina_list_append(files, full);
+ }
+ }
+ if (files)
+ { // only run if we have files
+ if (opt_f) op_run("rm", files, NULL);
+ else op_run("trash", files, NULL);
+ EINA_LIST_FREE(files, full) free(full);
+ }
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ {
+ if ((args[1]) && (args[1][0]))
+ { // we have 1 or more args - complete last
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ }
+ else if (!strcmp(args[0], "unlink"))
+ { // built-in cmd: unlink file1 [file2] [file3] ...
+ _cmd_typebuf_icon_send("std:edit-delete");
+ if ((op) && (!strcmp(op, "run")))
+ {
+ if ((args[1]) && (args[1][0]))
+ {
+ Eina_List *files = NULL;
+ int i;
+ char *full = NULL;
+
+ for (i = 1; args[i]; i++)
+ {
+ const char *arg = args[i];
+
+ if (arg[0])
+ { // it's a file - convert to path if needed
+ full = _path_arg_rel_to_abs(arg);
+ if (full) files = eina_list_append(files, full);
+ }
+ }
+ if (files)
+ { // only run if we have files
+ op_run("rm", files, NULL);
+ EINA_LIST_FREE(files, full) free(full);
+ }
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ {
+ if ((args[1]) && (args[1][0]))
+ { // we have 1 or more args - complete last
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ }
+ else if (!strcmp(args[0], "mv"))
+ { // built-in cmd: mv file1 [file2] [file3] [destdir] ...
+ // built-in cmd: mv file newfilename
+ // at least 2 args. last arg is dest dir OR new filename
+ _cmd_typebuf_icon_send("std:edit-rename");
+ // _op_run("mv", files, NULL);
+ }
+ else if (!strcmp(args[0], "cp"))
+ { // built-in cmd: cp file1 [file2] [file3] [destdir] ...
+ // built-in cmd: cp file copyfilename
+ // at least 2 args. last arg is dest dir OR new copy filename
+ _cmd_typebuf_icon_send("std:edit-copy");
+ // _op_run("cp", files, NULL);
+ }
+ else if (!strcmp(args[0], "ln"))
+ { // built-in cmd: ln [-s] dest linkfilename
+ _cmd_typebuf_icon_send("std:insert-link");
+ if ((op) && (!strcmp(op, "run")))
+ { // must have 2 args minimum
+ if ((args[1]) && (args[1][0]) && (args[2]) && (args[2][0]))
+ {
+ Eina_List *files = NULL;
+ int i;
+ char *full = NULL;
+
+ for (i = 1; args[i]; i++)
+ {
+ const char *arg = args[i];
+
+ if (arg[0] == '-')
+ { // its an option - ignore it - we ALWAYS do -s
+ }
+ else if (arg[0])
+ { // it's a file - convert to path if needed
+ if (!files) full = strdup(arg);
+ else full = _path_arg_rel_to_abs(arg);
+ if (full) files = eina_list_append(files, full);
+ }
+ }
+ if (files)
+ { // only run if we have files
+ char *link_src = eina_list_nth(files, 0);
+ const char *link_file = eina_list_nth(files, 1);
+ if (link_src && link_file)
+ {
+ status_begin();
+ status_op("ln");
+ fs_ln(link_src, link_file, EINA_FALSE);
+ status_end();
+ }
+ EINA_LIST_FREE(files, full) free(full);
+ }
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ { // complete last arg
+ if ((args[1]) && (args[1][0]))
+ { // we have 1 or more args
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ }
+ else if (!strcmp(args[0], "cd"))
+ { // built-in cmd: cd dirname
+ _cmd_typebuf_icon_send("std:folder");
+ if ((op) && (!strcmp(op, "run")))
+ { // only support 1 arg (first) if there - "cd arg"
+ if ((args[1]) && (args[1][0])) _typebuf_cd(args[1]);
+ else
+ { // no arg - go to $HOME
+ const char *home = getenv("HOME");
+ if (home) _typebuf_cd(home);
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ { // complete last arg
+ if ((args[1]) && (args[1][0]))
+ { // we have 1 or more args
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ }
+ else if (args[0])
+ { // generic typebuf matches a desktop file for an app/command you
+ // have installed and indexed - thus can be extended with more
+ // installed desktop files that are found/indexed
+ // first try - match by the exec command in the desktop
+ Efreet_Desktop *d = efreet_util_desktop_exec_find(args[0]);
+
+ if (!d) // that didn't work
+ { // can't find by exec - let's find by desktop filename/oid
+ char buf[1024];
+
+ snprintf(buf, sizeof(buf), "%s.desktop", args[0]);
+ d = efreet_util_desktop_file_id_find(buf);
+ }
+ // if that didn't work find by name field in desktop
+ if (!d) d = efreet_util_desktop_name_find(args[0]);
+ if (d)
+ { // found some desktop matching the cmd
+ Eina_Strbuf *buf2 = eina_strbuf_new();
+
+ if (buf2)
+ { // provide the icon from the desktop file for typebuf
+ eina_strbuf_append_printf(buf2, "std:%s", d->icon);
+ _cmd_typebuf_icon_send(eina_strbuf_string_get(buf2));
+ eina_strbuf_free(buf2);
+ }
+ if ((op) && (!strcmp(op, "run")))
+ { // ask front end to "run" files provided as args
+ Eina_Strbuf *strbuf = cmd_strbuf_new("file-run");
+
+ if (strbuf)
+ {
+ int i;
+ const char *mondir = ecore_file_monitor_path_get(mon);
+
+ if (mondir)
+ { // cwd is this dir for cmds as if we were in a
+ // terminal in cwd
+ cmd_strbuf_append(strbuf, "cwd", mondir);
+ cmd_strbuf_append(strbuf, "open-with", d->orig_path);
+ // add args as files
+ for (i = 1; args[i]; i++)
+ {
+ if ((args[i]) && (args[i][0]))
+ cmd_strbuf_append(strbuf, "path", args[i]);
+ }
+ // send file-run cmd back to front end
+ cmd_strbuf_print_consume(strbuf);
+ }
+ }
+ }
+ else if ((op) && (!strcmp(op, "complete")))
+ { // complete last arg as file
+ if ((args[1]) && (args[1][0]))
+ {
+ Eina_Strbuf *strbuf = cmd_strbuf_new("typebuf-set");
+ if (_complete_last_arg_path_cmd(args, strbuf, "string"))
+ cmd_strbuf_print_consume(strbuf);
+ else eina_strbuf_free(strbuf);
+ }
+ }
+ efreet_desktop_free(d);
+ }
+ }
+ // for (p = args; *p != NULL; p++)
+ // fprintf(stderr, "XXX:ZZZ: [%s]\n", *p);
+ }
+ free(*args);
+ free(args);
+}
diff --git a/src/backends/default/typebuf.h b/src/backends/default/typebuf.h
new file mode 100644
index 0000000..a2a9ea4
--- /dev/null
+++ b/src/backends/default/typebuf.h
@@ -0,0 +1,8 @@
+#ifndef TYPEBUF_H
+#define TYPEBUF_H
+
+#include "cmd.h"
+
+void typebuf_cmd(Cmd *c);
+
+#endif
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.