aboutsummaryrefslogtreecommitdiff
path: root/cmd-if-shell.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-23 19:24:42 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-23 19:24:42 +0000
commit497b27dafb7f531db3b82d6bf061279c599e69ae (patch)
treedf7c47e248e38e036a32d1c2381292cea17d6f91 /cmd-if-shell.c
parent357da035b9d052b4cba8db806c6237272ade6673 (diff)
downloadrtmux-497b27dafb7f531db3b82d6bf061279c599e69ae.tar.gz
rtmux-497b27dafb7f531db3b82d6bf061279c599e69ae.tar.bz2
rtmux-497b27dafb7f531db3b82d6bf061279c599e69ae.zip
Expand format variables in the run-shell and if-shell shell commands, from
Thiago Padilha.
Diffstat (limited to 'cmd-if-shell.c')
-rw-r--r--cmd-if-shell.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index 6f0b151a..02c19976 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -36,8 +36,8 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
- "", 2, 3,
- "shell-command command [command]",
+ "t:", 2, 3,
+ CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
NULL,
NULL,
@@ -55,7 +55,22 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct cmd_if_shell_data *cdata;
- const char *shellcmd = args->argv[0];
+ const char *shellcmd;
+ struct session *s;
+ struct winlink *wl;
+ struct window_pane *wp;
+ struct format_tree *ft;
+
+ wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
+ if (wl == NULL)
+ return (CMD_RETURN_ERROR);
+
+ ft = format_create();
+ format_session(ft, s);
+ format_winlink(ft, s, wl);
+ format_window_pane(ft, wp);
+ shellcmd = format_expand(ft, args->argv[0]);
+ format_free(ft);
cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]);
@@ -68,6 +83,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_ref_ctx(ctx);
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
+ free(shellcmd);
return (CMD_RETURN_YIELD); /* don't let client exit */
}