From 11e3f43264e01d5eb4450ac03aed253bd1b772b1 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Mon, 17 Feb 2014 00:21:49 +0100 Subject: [PATCH] Use all options also for new spawned instances (#64). The --cmd option was not given to new vimb instance if a link was opened into a new window. This was not obvious and inconsistent compared to the other options. --- doc/vimb.1 | 4 +--- src/main.c | 27 +++++++++++++++------------ src/main.h | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/doc/vimb.1 b/doc/vimb.1 index 5f9a020..589a53b 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -17,9 +17,7 @@ Mandatory arguments to long options are mandatory for short options too. .TP .BI "\-C, \-\-cmd " "CMD" Run \fICMD\fP as ex command line right before the first page is loaded. -Several ex commands can be used separated by "|". Note that this command is -not run in further spawned instances of vimb. If a link is opened into a new -browser instance, the \fICMD\fP does not affect the new instance. +Several ex commands can be used separated by "|". Example: `vimb --cmd "set cookie-accept=origin|set header=Referer,DNT=1"` .TP diff --git a/src/main.c b/src/main.c index 0e666f7..56ec589 100644 --- a/src/main.c +++ b/src/main.c @@ -175,17 +175,22 @@ gboolean vb_load_uri(const Arg *arg) if (arg->i == VB_TARGET_NEW) { guint i = 0; - char *cmd[7], xid[64]; + char *cmd[9]; cmd[i++] = *args; if (vb.embed) { - cmd[i++] = "-e"; + char xid[64]; snprintf(xid, LENGTH(xid), "%u", (int)vb.embed); + cmd[i++] = "-e"; cmd[i++] = xid; } - if (vb.custom_config) { + if (vb.config.file) { cmd[i++] = "-c"; - cmd[i++] = vb.custom_config; + cmd[i++] = vb.config.file; + } + if (vb.config.autocmd) { + cmd[i++] = "-C"; + cmd[i++] = vb.config.autocmd; } cmd[i++] = uri; cmd[i++] = NULL; @@ -748,8 +753,8 @@ static void init_files(void) { char *path = util_get_config_dir(); - if (vb.custom_config) { - char *rp = realpath(vb.custom_config, NULL); + if (vb.config.file) { + char *rp = realpath(vb.config.file, NULL); vb.files[FILES_CONFIG] = g_strdup(rp); free(rp); } else { @@ -978,12 +983,10 @@ int main(int argc, char *argv[]) static char *winid = NULL; static gboolean ver = false; static GError *err; - static char *cmd = NULL; - vb.custom_config = NULL; static GOptionEntry opts[] = { - {"cmd", 'C', 0, G_OPTION_ARG_STRING, &cmd, "Ex command run before first page is loaded", NULL}, - {"config", 'c', 0, G_OPTION_ARG_STRING, &vb.custom_config, "Custom cufiguration file", NULL}, + {"cmd", 'C', 0, G_OPTION_ARG_STRING, &vb.config.autocmd, "Ex command run before first page is loaded", NULL}, + {"config", 'c', 0, G_OPTION_ARG_STRING, &vb.config.file, "Custom cufiguration file", NULL}, {"embed", 'e', 0, G_OPTION_ARG_STRING, &winid, "Reparents to window specified by xid", NULL}, {"version", 'v', 0, G_OPTION_ARG_NONE, &ver, "Print version", NULL}, {NULL} @@ -1011,8 +1014,8 @@ int main(int argc, char *argv[]) init_core(); /* process the --cmd if this was given */ - if (cmd) { - ex_run_string(cmd); + if (vb.config.autocmd) { + ex_run_string(vb.config.autocmd); } /* command line argument: URL */ diff --git a/src/main.h b/src/main.h index 7c2f5c3..f39269c 100644 --- a/src/main.h +++ b/src/main.h @@ -298,6 +298,8 @@ typedef struct { GHashTable *headers; /* holds user defined header appended to requests */ char *nextpattern; /* regex patter nfor prev link matching */ char *prevpattern; /* regex patter nfor next link matching */ + char *file; /* path to the custome config file */ + char *autocmd; /* command given by --cmd option */ } Config; typedef struct { @@ -328,7 +330,6 @@ typedef struct { #else GdkNativeWindow embed; #endif - char *custom_config; } VbCore; /* main object */ -- 2.20.1