Commit 4e46cafc authored by Christoph Stelz's avatar Christoph Stelz Committed by Sebastian Ramacher

Add --find option to CLI

parent fde4abea
Pipeline #285 passed with stages
in 1 minute and 50 seconds
......@@ -20,6 +20,9 @@
with 1, and negative numbers indicate page numbers starting from the end
of the document, -1 being the last page.
-f, --find=string
Opens the document and searches for the given string.
-l, --log-level=level
Set log level (debug, info, warning, error)
......
zathura [-e XID] [-c PATH] [-d PATH] [-p PATH] [-w PASSWORD] [-P NUMBER]
[--fork] [-l LEVEL] [-s] [-x CMD] [--synctex-forward INPUT] [--synctex-pid PID]
[-f STRING]
<files>
......@@ -253,7 +253,7 @@ cmd_open(girara_session_t* session, girara_list_t* argument_list)
document_open_idle(zathura, girara_list_nth(argument_list, 0),
(argc == 2) ? girara_list_nth(argument_list, 1) : NULL,
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL);
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL, NULL);
} else {
girara_notify(session, GIRARA_ERROR, _("No arguments given."));
return false;
......
......@@ -221,7 +221,7 @@ handle_open_document(zathura_t* zathura, GVariant* parameters,
document_open_idle(zathura, filename,
strlen(password) > 0 ? password : NULL,
page,
NULL, NULL);
NULL, NULL, NULL);
g_free(filename);
g_free(password);
......
......@@ -135,6 +135,7 @@ main(int argc, char* argv[])
gchar* synctex_editor = NULL;
gchar* synctex_fwd = NULL;
gchar* mode = NULL;
gchar* search_string = NULL;
bool forkback = false;
bool print_version = false;
int page_number = ZATHURA_PAGE_NUMBER_UNSPECIFIED;
......@@ -156,6 +157,7 @@ main(int argc, char* argv[])
{ "synctex-forward", '\0', 0, G_OPTION_ARG_STRING, &synctex_fwd, _("Move to given synctex position"), "position" },
{ "synctex-pid", '\0', 0, G_OPTION_ARG_INT, &synctex_pid, _("Highlight given position in the given process"), "pid" },
{ "mode", '\0', 0, G_OPTION_ARG_STRING, &mode, _("Start in a non-default mode"), "mode" },
{ "find", 'f', 0, G_OPTION_ARG_STRING, &search_string, _("Search for the given phrase and display results"), "string" },
{ NULL, '\0', 0, 0, NULL, NULL, NULL }
};
......@@ -297,7 +299,12 @@ main(int argc, char* argv[])
--page_number;
}
document_open_idle(zathura, argv[file_idx], password, page_number, mode,
synctex_fwd);
synctex_fwd, search_string);
} else if (search_string != NULL) {
girara_error("Can not use find argument when no file is given");
ret = -1;
zathura_free(zathura);
goto free_and_ret;
}
/* run zathura */
......@@ -316,6 +323,7 @@ free_and_ret:
g_free(synctex_editor);
g_free(synctex_fwd);
g_free(mode);
g_free(search_string);
return ret;
}
......@@ -27,6 +27,7 @@
#include "bookmarks.h"
#include "callbacks.h"
#include "config.h"
#include "commands.h"
#ifdef WITH_SQLITE
#include "database-sqlite.h"
#endif
......@@ -56,6 +57,7 @@ typedef struct zathura_document_info_s {
int page_number;
char* mode;
char* synctex;
char* search_string;
} zathura_document_info_t;
......@@ -76,6 +78,7 @@ free_document_info(zathura_document_info_t* document_info)
g_free(document_info->password);
g_free(document_info->mode);
g_free(document_info->synctex);
g_free(document_info->search_string);
g_free(document_info);
}
......@@ -879,6 +882,14 @@ document_info_open(gpointer data)
girara_error("Unknown mode: %s", document_info->mode);
}
}
if (document_info->search_string != NULL) {
girara_argument_t search_arg;
search_arg.n = 1; // Forward search
search_arg.data = NULL;
cmd_search(document_info->zathura->ui.session, document_info->search_string,
&search_arg);
}
}
}
......@@ -1297,7 +1308,8 @@ document_open_synctex(zathura_t* zathura, const char* path, const char* uri,
void
document_open_idle(zathura_t* zathura, const char* path, const char* password,
int page_number, const char* mode, const char* synctex)
int page_number, const char* mode, const char* synctex,
const char *search_string)
{
g_return_if_fail(zathura != NULL);
g_return_if_fail(path != NULL);
......@@ -1319,6 +1331,9 @@ document_open_idle(zathura_t* zathura, const char* path, const char* password,
if (synctex != NULL) {
document_info->synctex = g_strdup(synctex);
}
if (search_string != NULL) {
document_info->search_string = g_strdup(search_string);
}
gdk_threads_add_idle(document_info_open, document_info);
}
......
......@@ -342,7 +342,8 @@ bool document_open_synctex(zathura_t* zathura, const char* path, const char* uri
*/
void document_open_idle(zathura_t* zathura, const char* path,
const char* password, int page_number,
const char* mode, const char* synctex);
const char* mode, const char* synctex,
const char* search_string);
/**
* Save a open file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment