Use all options also for new spawned instances (#64).
authorDaniel Carl <danielcarl@gmx.de>
Sun, 16 Feb 2014 23:21:49 +0000 (00:21 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 16 Feb 2014 23:21:49 +0000 (00:21 +0100)
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
src/main.c
src/main.h

index 5f9a020..589a53b 100644 (file)
@@ -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
index 0e666f7..56ec589 100644 (file)
@@ -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 */
index 7c2f5c3..f39269c 100644 (file)
@@ -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 */