mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-16 02:35:51 +01:00
Add --find option to CLI
This commit is contained in:
parent
fde4abeac5
commit
4e46cafc98
7 changed files with 33 additions and 5 deletions
|
@ -20,6 +20,9 @@
|
||||||
with 1, and negative numbers indicate page numbers starting from the end
|
with 1, and negative numbers indicate page numbers starting from the end
|
||||||
of the document, -1 being the last page.
|
of the document, -1 being the last page.
|
||||||
|
|
||||||
|
-f, --find=string
|
||||||
|
Opens the document and searches for the given string.
|
||||||
|
|
||||||
-l, --log-level=level
|
-l, --log-level=level
|
||||||
Set log level (debug, info, warning, error)
|
Set log level (debug, info, warning, error)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
zathura [-e XID] [-c PATH] [-d PATH] [-p PATH] [-w PASSWORD] [-P NUMBER]
|
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]
|
[--fork] [-l LEVEL] [-s] [-x CMD] [--synctex-forward INPUT] [--synctex-pid PID]
|
||||||
|
[-f STRING]
|
||||||
<files>
|
<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),
|
document_open_idle(zathura, girara_list_nth(argument_list, 0),
|
||||||
(argc == 2) ? girara_list_nth(argument_list, 1) : NULL,
|
(argc == 2) ? girara_list_nth(argument_list, 1) : NULL,
|
||||||
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL);
|
ZATHURA_PAGE_NUMBER_UNSPECIFIED, NULL, NULL, NULL);
|
||||||
} else {
|
} else {
|
||||||
girara_notify(session, GIRARA_ERROR, _("No arguments given."));
|
girara_notify(session, GIRARA_ERROR, _("No arguments given."));
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -221,7 +221,7 @@ handle_open_document(zathura_t* zathura, GVariant* parameters,
|
||||||
document_open_idle(zathura, filename,
|
document_open_idle(zathura, filename,
|
||||||
strlen(password) > 0 ? password : NULL,
|
strlen(password) > 0 ? password : NULL,
|
||||||
page,
|
page,
|
||||||
NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
g_free(password);
|
g_free(password);
|
||||||
|
|
||||||
|
|
|
@ -135,6 +135,7 @@ main(int argc, char* argv[])
|
||||||
gchar* synctex_editor = NULL;
|
gchar* synctex_editor = NULL;
|
||||||
gchar* synctex_fwd = NULL;
|
gchar* synctex_fwd = NULL;
|
||||||
gchar* mode = NULL;
|
gchar* mode = NULL;
|
||||||
|
gchar* search_string = NULL;
|
||||||
bool forkback = false;
|
bool forkback = false;
|
||||||
bool print_version = false;
|
bool print_version = false;
|
||||||
int page_number = ZATHURA_PAGE_NUMBER_UNSPECIFIED;
|
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-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" },
|
{ "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" },
|
{ "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 }
|
{ NULL, '\0', 0, 0, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -297,7 +299,12 @@ main(int argc, char* argv[])
|
||||||
--page_number;
|
--page_number;
|
||||||
}
|
}
|
||||||
document_open_idle(zathura, argv[file_idx], password, page_number, mode,
|
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 */
|
/* run zathura */
|
||||||
|
@ -316,6 +323,7 @@ free_and_ret:
|
||||||
g_free(synctex_editor);
|
g_free(synctex_editor);
|
||||||
g_free(synctex_fwd);
|
g_free(synctex_fwd);
|
||||||
g_free(mode);
|
g_free(mode);
|
||||||
|
g_free(search_string);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "bookmarks.h"
|
#include "bookmarks.h"
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "commands.h"
|
||||||
#ifdef WITH_SQLITE
|
#ifdef WITH_SQLITE
|
||||||
#include "database-sqlite.h"
|
#include "database-sqlite.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -56,6 +57,7 @@ typedef struct zathura_document_info_s {
|
||||||
int page_number;
|
int page_number;
|
||||||
char* mode;
|
char* mode;
|
||||||
char* synctex;
|
char* synctex;
|
||||||
|
char* search_string;
|
||||||
} zathura_document_info_t;
|
} 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->password);
|
||||||
g_free(document_info->mode);
|
g_free(document_info->mode);
|
||||||
g_free(document_info->synctex);
|
g_free(document_info->synctex);
|
||||||
|
g_free(document_info->search_string);
|
||||||
g_free(document_info);
|
g_free(document_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,6 +882,14 @@ document_info_open(gpointer data)
|
||||||
girara_error("Unknown mode: %s", document_info->mode);
|
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
|
void
|
||||||
document_open_idle(zathura_t* zathura, const char* path, const char* password,
|
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(zathura != NULL);
|
||||||
g_return_if_fail(path != 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) {
|
if (synctex != NULL) {
|
||||||
document_info->synctex = g_strdup(synctex);
|
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);
|
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,
|
void document_open_idle(zathura_t* zathura, const char* path,
|
||||||
const char* password, int page_number,
|
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
|
* Save a open file
|
||||||
|
|
Loading…
Reference in a new issue