diff src/editors.c @ 737:8a8873e7a552

Make shell command and its option rc file options instead of hardcoded strings. 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.
author zas_
date Thu, 22 May 2008 20:22:13 +0000
parents fa8f7d7396cf
children 477f48ba28d8
line wrap: on
line diff
--- a/src/editors.c	Thu May 22 13:00:45 2008 +0000
+++ b/src/editors.c	Thu May 22 20:22:13 2008 +0000
@@ -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;
@@ -579,14 +577,30 @@
 
 	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 */