diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-12-06 18:46:57 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-12-06 18:46:57 +0100 |
commit | c419594e8aff0fdc17c21e9313169e08f3050a73 (patch) | |
tree | 32504f7c2f5efff1c7f883437fa66282499e17b9 | |
parent | c150136f5b772c35a633afadecf6e3e491ff4ae4 (diff) |
support executing commands both through shell and directly
-rw-r--r-- | README | 13 | ||||
-rw-r--r-- | examples/config/uzbl/config | 2 | ||||
-rw-r--r-- | uzbl-core.c | 29 |
3 files changed, 30 insertions, 14 deletions
@@ -291,12 +291,21 @@ The above example demonstrates two things: Command substitution will launch any commands and substitute the call with the return value of the command. +There are two methods: -Uzbl will substitute any commands enclosed within @( )@: + * through a shell: enclose commands with @( )@ (quotes escaping is handled by uzbl): print Command substitution: @(uname -a)@ -You can access any uzbl variable from within a command substitution: +This method allows you to use posix shell syntax in your commands + + * directly: + + print Command substitution: @(+uname -a)@ + +This example will execute uname directly + +Note that you can access any uzbl variable from within a command substitution: print @(echo -n 'Accessing the show_status var from an external script, value: @show_status')@ diff --git a/examples/config/uzbl/config b/examples/config/uzbl/config index 5585195..94b1e73 100644 --- a/examples/config/uzbl/config +++ b/examples/config/uzbl/config @@ -108,7 +108,7 @@ set status_format = <span font_family="monospace">@mode_section @keycmd_sect # === Core settings ========================================================== -set useragent = Uzbl (Webkit @WEBKIT_MAJOR.@WEBKIT_MINOR.@WEBKIT_MICRO) (@(uname -o)@ @(uname -m)@ [@ARCH_UZBL]) (Commit @COMMIT) +set useragent = Uzbl (Webkit @WEBKIT_MAJOR.@WEBKIT_MINOR.@WEBKIT_MICRO) (@(+uname -o)@ @(+uname -m)@ [@ARCH_UZBL]) (Commit @COMMIT) set fifo_dir = /tmp set socket_dir = /tmp diff --git a/uzbl-core.c b/uzbl-core.c index 42e274e..01d0803 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -266,17 +266,24 @@ expand(const char *s, guint recurse) { } else if(recurse != 1 && etype == EXP_EXPR) { - - mycmd = expand(ret, 1); - gchar *quoted = g_shell_quote(mycmd); - gchar *tmp = g_strdup_printf("%s %s", - uzbl.behave.shell_cmd?uzbl.behave.shell_cmd:"/bin/sh -c", - quoted); - g_spawn_command_line_sync(tmp, &cmd_stdout, NULL, NULL, &err); - g_free(mycmd); - g_free(quoted); - g_free(tmp); - + /* execute program directly */ + if(ret[0] == '+') { + mycmd = expand(ret+1, 1); + g_spawn_command_line_sync(mycmd, &cmd_stdout, NULL, NULL, &err); + g_free(mycmd); + } + /* execute program through shell, quote it first */ + else { + mycmd = expand(ret, 1); + gchar *quoted = g_shell_quote(mycmd); + gchar *tmp = g_strdup_printf("%s %s", + uzbl.behave.shell_cmd?uzbl.behave.shell_cmd:"/bin/sh -c", + quoted); + g_spawn_command_line_sync(tmp, &cmd_stdout, NULL, NULL, &err); + g_free(mycmd); + g_free(quoted); + g_free(tmp); + } if (err) { g_printerr("error on running command: %s\n", err->message); g_error_free (err); |