From 98ae34f1dcc671bc691c40fa9896ab5624818e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Techet?= Date: Thu, 8 Jan 2015 22:32:17 +0100 Subject: [PATCH] Perform execute using the default terminal application on OS X In order to execute the runner script using the terminal application, the script has to be executable, otherwise it's not executed. In addition, when the terminal application starts, it sets $HOME as the working directory. For this reason the working directory has to be set in the runner script (to avoid additional ifdefs, this part is shared with other unix systems where the additional "cd" shouldn't matter). --- src/build.c | 22 +++++++++++++++++----- src/keyfile.c | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/build.c b/src/build.c index 65f75ca8..0645d604 100644 --- a/src/build.c +++ b/src/build.c @@ -128,7 +128,7 @@ static guint build_items_count = 9; static void build_exit_cb(GPid child_pid, gint status, gpointer user_data); static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data); #endif -static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose, GError **error); +static gboolean build_create_shellscript(const gchar *fname, const gchar *working_dir, const gchar *cmd, gboolean autoclose, GError **error); static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir); static void set_stop_button(gboolean stop); static void run_exit_cb(GPid child_pid, gint status, gpointer user_data); @@ -937,7 +937,7 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript, /* RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because it * contains no umlauts */ tmp = g_build_filename(working_dir, RUN_SCRIPT_CMD, NULL); - result = build_create_shellscript(tmp, cmd_string, autoclose, &error); + result = build_create_shellscript(tmp, working_dir, cmd_string, autoclose, &error); if (! result) { ui_set_statusbar(TRUE, _("Failed to execute \"%s\" (start-script could not be created: %s)"), @@ -1279,13 +1279,15 @@ static void set_file_error_from_errno(GError **error, gint err, const gchar *pre /* write a little shellscript to call the executable (similar to anjuta_launcher but "internal") * fname is the full file name (including path) for the script to create */ -static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose, GError **error) +static gboolean build_create_shellscript(const gchar *fname, const gchar *working_dir, const gchar *cmd, gboolean autoclose, GError **error) { FILE *fp; gchar *str; gboolean success = TRUE; #ifdef G_OS_WIN32 gchar *expanded_cmd; +#else + gchar *escaped_dir; #endif fp = g_fopen(fname, "w"); @@ -1300,11 +1302,13 @@ static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, g str = g_strdup_printf("%s\n\n%s\ndel \"%%0\"\n\npause\n", expanded_cmd, (autoclose) ? "" : "pause"); g_free(expanded_cmd); #else + escaped_dir = g_strescape(working_dir, NULL); str = g_strdup_printf( - "#!/bin/sh\n\nrm $0\n\n%s\n\necho \"\n\n------------------\n(program exited with code: $?)\" \ - \n\n%s\n", cmd, (autoclose) ? "" : + "#!/bin/sh\n\nrm $0\n\ncd \'%s\'\n\n%s\n\necho \"\n\n------------------\n(program exited with code: $?)\" \ + \n\n%s\n", escaped_dir, cmd, (autoclose) ? "" : "\necho \"Press return to continue\"\n#to be more compatible with shells like " "dash\ndummy_var=\"\"\nread dummy_var"); + g_free(escaped_dir); #endif if (fputs(str, fp) < 0) @@ -1320,6 +1324,14 @@ static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, g set_file_error_from_errno(error, errno, "Failed to close file"); success = FALSE; } +#ifdef __APPLE__ + if (g_chmod(fname, 0777) != 0) + { + if (error && ! *error) /* don't set error twice */ + set_file_error_from_errno(error, errno, "Failed to make file executable"); + success = FALSE; + } +#endif return success; } diff --git a/src/keyfile.c b/src/keyfile.c index 157ea324..84a93e19 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -74,6 +74,8 @@ #define GEANY_DEFAULT_TOOLS_MAKE "make" #ifdef G_OS_WIN32 #define GEANY_DEFAULT_TOOLS_TERMINAL "cmd.exe /Q /C %c" +#elif defined(__APPLE__) +#define GEANY_DEFAULT_TOOLS_TERMINAL "open -a terminal %c" #else #define GEANY_DEFAULT_TOOLS_TERMINAL "xterm -e \"/bin/sh %c\"" #endif