Here's a quick patch that's gives tracker-search the "-exec" parameter
available in GNU find. You can find more information about this
parameter from find's man page, here's a quick example:
# tracker-search foobar -exec basename {} \;
(--exec also works, -exec is for those fingers that are trained to
only type dash once when exec'ing)
Index: src/libtracker/tracker-search.c
===================================================================
RCS file: /cvs/gnome/tracker/src/libtracker/tracker-search.c,v
retrieving revision 1.15
diff -u -p -r1.15 tracker-search.c
--- src/libtracker/tracker-search.c 5 Nov 2006 23:31:39 -0000 1.15
+++ src/libtracker/tracker-search.c 11 Nov 2006 23:26:39 -0000
@@ -19,11 +19,11 @@
#include <locale.h>
#include <glib.h>
+#include <string.h>
#include "../libtracker/tracker.h"
static gint limit = 0;
-static gchar **terms = NULL;
static gchar *service = NULL;
static gboolean detailed;
@@ -31,14 +31,13 @@ static GOptionEntry entries[] = {
{"limit", 'l', 0, G_OPTION_ARG_INT, &limit, "limit the number of results showed", "limit"},
{"service", 's', 0, G_OPTION_ARG_STRING, &service, "search from a specific service", "service"},
{"detailed", 'd', 0, G_OPTION_ARG_NONE, &detailed, "Show more detailed results with service and mime type as well", NULL},
- {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &terms, "search terms", NULL},
+ //{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &terms, "search terms", NULL},
{NULL}
};
static void
get_meta_table_data (gpointer value)
-
{
char **meta, **meta_p;
@@ -73,6 +72,9 @@ main (int argc, char **argv)
gchar **result;
char **p_strarray;
GPtrArray *out_array = NULL;
+ int i;
+ gboolean build_exec_command;
+ gchar *exec_command;
setlocale (LC_ALL, "");
@@ -80,6 +82,8 @@ main (int argc, char **argv)
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, &error);
+
+#if 0
if (error) {
g_printerr ("invalid arguments: %s\n", error->message);
return 1;
@@ -89,6 +93,7 @@ main (int argc, char **argv)
g_printerr ("missing search terms, try --help for help\n");
return 1;
}
+#endif
if (limit <= 0)
limit = 512;
@@ -119,7 +124,50 @@ main (int argc, char **argv)
type = SERVICE_OTHER_FILES;
}
- search = g_strjoinv (" ", terms);
+ search = NULL;
+ exec_command = NULL;
+ build_exec_command = FALSE;
+ for (i =1; i < argc; i++) {
+ if (strcmp (argv[i], "-exec") == 0 || strcmp (argv[i], "--exec") == 0) {
+ build_exec_command = TRUE;
+ }
+ else if (build_exec_command) {
+ if (strcmp (argv[i], ";") == 0) {
+ build_exec_command = FALSE;
+ }
+ else {
+ if (exec_command) {
+ gchar *tmp = g_strconcat (exec_command, " ", argv[i], NULL);
+ g_free (exec_command);
+ exec_command = tmp;
+ }
+ else {
+ exec_command = g_strdup (argv[i]);
+ }
+ }
+ }
+ else if (argv[i][0] == '-') {
+ g_printerr ("invalid arguments: %s\n", argv[i]);
+ return 1;
+ }
+ else {
+ if (search) {
+ gchar *tmp = g_strconcat (search, " ", argv[i], NULL);
+ g_free (search);
+ search = tmp;
+ }
+ else {
+ search = g_strdup (argv[i]);
+ }
+ }
+ }
+
+ if (!search) {
+ g_printerr ("missing search terms, try --help for help\n");
+ return 1;
+ }
+
+ error = NULL;
if (!detailed) {
result = tracker_search_text (client, -1, type, search, 0, limit, &error);
@@ -160,7 +208,18 @@ main (int argc, char **argv)
if (!s)
continue;
- g_print ("%s\n", s);
+ if (exec_command) {
+ gchar **split = g_strsplit (exec_command, "{}", -1);
+ gchar *e = g_shell_quote (s);
+ gchar *cmd = g_strjoinv (e, split);
+ g_free (e);
+ g_strfreev (split);
+ g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL);
+ g_free (cmd);
+ }
+ else {
+ g_print ("%s\n", s);
+ }
g_free (s);
}
_______________________________________________
tracker-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tracker-list