diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-06-14 19:08:06 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2015-06-14 19:08:06 +0200 |
commit | 15409bae5ffdfce4ef17c4ccf14c8cd4c1b8f37e (patch) | |
tree | 852b915a69d57679a05ef5fec0ee6608cdcf2dee /src/spawn.cpp | |
parent | 573951d4e2bb4fb1d14212583a59ce76344593cc (diff) | |
download | sciteco-15409bae5ffdfce4ef17c4ccf14c8cd4c1b8f37e.tar.gz |
handle environment variables more consistently
* the registers beginning with "$" are exported into sub-process
environments. Therefore macros can now modify the environment
(variables) of commands executed via EC/EG.
A variable can be modified temporarily, e.g.:
[[$FOO] ^U[$FOO]bar$ EC...$ ][$FOO]
* SciTECO accesses the global environment registers instead of
using g_getenv(). Therefore now, tilde-expansion will always
use the current value of the "$HOME" register.
Previously, both register and environment variable could diverge.
* This effectively fully maps the process environment to a subset of
Q-Registers beginning with "$".
* This hasn't been implemented by mapping those registers to
special implementations that updates the process environment
directly, since g_setenv() is non-thread-safe on UNIX
and we're expected to have threads soon - at least in the GTK+ UI.
Diffstat (limited to 'src/spawn.cpp')
-rw-r--r-- | src/spawn.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/spawn.cpp b/src/spawn.cpp index 9f951f5..b5d64e9 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -198,6 +198,14 @@ parse_shell_command_line(const gchar *cmdline, GError **error) * \(lq0,128ED\(rq, and is recommended when writing cross-platform * macros using the EC command. * + * The spawned process inherits both \*(ST's current working + * directory and its environment variables. + * More precisely, \*(ST uses its environment registers + * to construct the spawned process' environment. + * Therefore it is also straight forward to change the working + * directory or some environment variable temporarily + * for a spawned process. + * * Note that when run interactively and subsequently rubbed * out, \*(ST can easily undo all changes to the editor * state. @@ -211,7 +219,7 @@ parse_shell_command_line(const gchar *cmdline, GError **error) * * In interactive mode, \*(ST performs TAB-completion * of filenames in the <command> string parameter but - * by doing so does not attempt any escaping of shell-relevant + * does not attempt any escaping of shell-relevant * characters like whitespaces. */ StateExecuteCommand::StateExecuteCommand() : StateExpectString() @@ -308,7 +316,7 @@ StateExecuteCommand::done(const gchar *str) */ return &States::start; - gchar **argv; + gchar **argv, **envp; static const gint flags = G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL; @@ -330,11 +338,14 @@ StateExecuteCommand::done(const gchar *str) if (!argv) goto gerror; - g_spawn_async_with_pipes(NULL, argv, NULL, (GSpawnFlags)flags, + envp = QRegisters::globals.get_environ(); + + g_spawn_async_with_pipes(NULL, argv, envp, (GSpawnFlags)flags, NULL, NULL, &pid, &stdin_fd, &stdout_fd, NULL, &ctx.error); + g_strfreev(envp); g_strfreev(argv); if (ctx.error) |