From a4a37be7894dde500b5a9098c39dc45ee30237be Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 6 Jan 2019 14:28:19 +0000 Subject: [PATCH] Addl fix #619: Man page disagrees with --remote-help https://github.com/BestImageViewer/geeqie/issues/619 The remote commands --file: and --view: will now display images in paths relative to the folder the remote command is executed from --- src/main.c | 11 +++++++++++ src/remote.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index c331a076..03aef4cc 100644 --- a/src/main.c +++ b/src/main.c @@ -222,6 +222,8 @@ static void parse_command_line(gint argc, gchar *argv[]) gboolean remote_do = FALSE; gchar *first_dir = NULL; gchar *app_lock; + gchar *pwd; + gchar *current_dir; command_line = g_new0(CommandLine, 1); @@ -442,7 +444,16 @@ static void parse_command_line(gint argc, gchar *argv[]) printf_term(TRUE, _("\nUse --remote-help for valid remote options.\n")); } + /* prepend the current dir the remote command was made from, + * for use by any remote command that needs it + */ + current_dir = g_get_current_dir(); + pwd = g_strconcat("--PWD:", current_dir, NULL); + remote_list = g_list_prepend(remote_list, pwd); + remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list); + g_free(pwd); + g_free(current_dir); } g_list_free(remote_list); diff --git a/src/remote.c b/src/remote.c index f281aea5..c5ecfdc9 100644 --- a/src/remote.c +++ b/src/remote.c @@ -73,6 +73,38 @@ struct _RemoteData { CollectionData *command_collection; }; +/* Remote commands from main.c are prepended with the current dir the remote + * command was made from. Some remote commands require this. The + * value is stored here + */ +static gchar *pwd = NULL; + +/** + * @brief Ensures file path is absolute. + * @param[in] filename Filepath, absolute or relative to calling directory + * @returns absolute path + * + * If first character of input filepath is not the directory + * separator, assume it as a relative path and prepend + * the directory the remote command was initiated from + * + * Return value must be freed with g_free() + */ +static gchar *set_pwd(gchar *filename) +{ + gchar *temp; + + if (strncmp(filename, G_DIR_SEPARATOR_S, 1) != 0) + { + temp = g_build_filename(pwd, filename, NULL); + } + else + { + temp = g_strdup(filename); + } + + return temp; +} static gboolean remote_server_client_cb(GIOChannel *source, GIOCondition condition, gpointer data) { @@ -614,7 +646,10 @@ static void gr_quit(const gchar *text, GIOChannel *channel, gpointer data) static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpointer data) { - gchar *filename = expand_tilde(text); + gchar *filename; + gchar *tilde_filename = expand_tilde(text); + + filename = set_pwd(tilde_filename); if (isfile(filename)) { @@ -638,6 +673,7 @@ static void gr_file_load_no_raise(const gchar *text, GIOChannel *channel, gpoint } g_free(filename); + g_free(tilde_filename); } static void gr_file_load(const gchar *text, GIOChannel *channel, gpointer data) @@ -974,10 +1010,14 @@ static void gr_get_destination(const gchar *text, GIOChannel *channel, gpointer static void gr_file_view(const gchar *text, GIOChannel *channel, gpointer data) { - gchar *filename = expand_tilde(text); + gchar *filename; + gchar *tilde_filename = expand_tilde(text); + + filename = set_pwd(tilde_filename); view_window_new(file_data_new_group(filename)); g_free(filename); + g_free(tilde_filename); } static void gr_list_clear(const gchar *text, GIOChannel *channel, gpointer data) @@ -1031,6 +1071,14 @@ static void gr_raise(const gchar *text, GIOChannel *channel, gpointer data) } } +static void gr_pwd(const gchar *text, GIOChannel *channel, gpointer data) +{ + LayoutWindow *lw = NULL; + + g_free(pwd); + pwd = g_strdup(text); +} + #ifdef HAVE_LUA static void gr_lua(const gchar *text, GIOChannel *channel, gpointer data) { @@ -1126,6 +1174,7 @@ static RemoteCommandEntry remote_commands[] = { #ifdef HAVE_LUA { NULL, "--lua:", gr_lua, TRUE, FALSE, N_(","), N_("run lua script on FILE") }, #endif + { NULL, "--PWD:", gr_pwd, TRUE, FALSE, N_(""), N_("for internal use only") }, { NULL, NULL, NULL, FALSE, FALSE, NULL, NULL } }; -- 2.20.1