Make shell command and its option rc file options instead of hardcoded strings.
authorLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 20:22:13 +0000 (20:22 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 22 May 2008 20:22:13 +0000 (20:22 +0000)
This allows users to modify the shell command that execute "editors".
Two new options appear in rc file:
- shell.path (default to "/bin/sh")
- shell.options (default to "-c")

These options can only be changed from the rc file, not at runtime.
Tests are made to check that shell.path is not empty and lead to
an executable file.

src/editors.c
src/main.c
src/main.h
src/options.h
src/rcfile.c

index bfb57bc..8ca1168 100644 (file)
@@ -27,8 +27,6 @@
 #define EDITOR_WINDOW_WIDTH 500
 #define EDITOR_WINDOW_HEIGHT 300
 
-#define COMMAND_SHELL "/bin/sh"
-#define COMMAND_OPT  "-c"
 
 
 typedef struct _EditorVerboseData EditorVerboseData;
@@ -577,16 +575,32 @@ static gint editor_command_one(const gchar *template, GList *list, EditorData *e
 
        ok = !(ed->flags & EDITOR_ERROR_MASK);
 
+       if (ok)
+               {
+               ok = (options->shell.path && *options->shell.path);
+               if (!ok) log_printf("ERROR: empty shell command\n");
+                       
+               if (ok)
+                       {
+                       ok = (access(options->shell.path, X_OK) == 0);
+                       if (!ok) log_printf("ERROR: cannot execute shell command '%s'\n", options->shell.path);
+                       }
+
+               if (!ok) ed->flags |= EDITOR_ERROR_CANT_EXEC;
+               }
+
        if (ok)
                {
                gchar *working_directory;
                gchar *args[4];
+               guint n = 0;
 
                working_directory = remove_level_from_path(fd->path);
-               args[0] = COMMAND_SHELL;
-               args[1] = COMMAND_OPT;
-               args[2] = command;
-               args[3] = NULL;
+               args[n++] = options->shell.path;
+               if (options->shell.options && *options->shell.options)
+                       args[n++] = options->shell.options;
+               args[n++] = command;
+               args[n] = NULL;
 
                ok = g_spawn_async_with_pipes(working_directory, args, NULL,
                                      G_SPAWN_DO_NOT_REAP_CHILD, /* GSpawnFlags */
index ab72153..e5bb205 100644 (file)
@@ -580,6 +580,9 @@ static void setup_default_options(void)
        sidecar_ext_add_defaults();
        options->layout.order = g_strdup("123");
        options->properties.tabs_order = g_strdup(info_tab_default_order());
+
+       options->shell.path = g_strdup(GQ_DEFAULT_SHELL_PATH);
+       options->shell.options = g_strdup(GQ_DEFAULT_SHELL_OPTIONS);
 }
 
 static void exit_program_final(void)
index 3485e88..96aa2e6 100644 (file)
@@ -90,6 +90,9 @@
 
 #define GQ_EDITOR_GENERIC_SLOTS 10
 
+#define GQ_DEFAULT_SHELL_PATH "/bin/sh"
+#define GQ_DEFAULT_SHELL_OPTIONS "-c"
+
 #define COLOR_PROFILE_INPUTS 4
 
 #define DEFAULT_THUMB_WIDTH    96
index 53a60f1..6c3d4ec 100644 (file)
@@ -110,6 +110,12 @@ struct _ConfOptions
        /* editors */
        Editor editor[GQ_EDITOR_SLOTS];
 
+       /* shell */
+       struct {
+               gchar *path;
+               gchar *options;
+       } shell;
+       
        /* file sorting */
        struct {
                SortType method;
index 9070871..b0aea7c 100644 (file)
@@ -548,6 +548,12 @@ void save_options(void)
        WRITE_INT(color_profile.screen_type);
        WRITE_CHAR(color_profile.screen_file);
 
+
+       WRITE_SUBTITLE("Shell command");
+       WRITE_CHAR(shell.path);
+       WRITE_CHAR(shell.options);
+
+
        WRITE_SUBTITLE("External Programs");
        secure_fprintf(ssi, "# Maximum of %d programs (external_1 through external_%d)\n", GQ_EDITOR_GENERIC_SLOTS, GQ_EDITOR_GENERIC_SLOTS);
        secure_fprintf(ssi, "# external_%d through external_%d are used for file ops\n", GQ_EDITOR_GENERIC_SLOTS + 1, GQ_EDITOR_SLOTS);
@@ -879,6 +885,10 @@ void load_options(void)
                READ_INT(color_profile.screen_type);
                READ_CHAR(color_profile.screen_file);
 
+               /* Shell command */
+               READ_CHAR(shell.path);
+               READ_CHAR(shell.options);
+
                /* External Programs */
 
                if (is_numbered_option(option, "external_", &i))