summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/cmd-if-shell.c24
-rw-r--r--usr.bin/tmux/cmd-run-shell.c19
-rw-r--r--usr.bin/tmux/tmux.116
3 files changed, 49 insertions, 10 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c
index ecec3a10d52..bd2b2a9eff1 100644
--- a/usr.bin/tmux/cmd-if-shell.c
+++ b/usr.bin/tmux/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-if-shell.c,v 1.18 2013/03/22 15:49:55 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.19 2013/03/24 09:33:35 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -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];
+ 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 */
}
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index c2ea3121857..e14bae5266e 100644
--- a/usr.bin/tmux/cmd-run-shell.c
+++ b/usr.bin/tmux/cmd-run-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-run-shell.c,v 1.16 2013/03/22 15:55:22 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.17 2013/03/24 09:33:35 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -75,14 +75,25 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
- const char *shellcmd = args->argv[0];
+ char *shellcmd;
+ struct session *s;
+ struct winlink *wl;
struct window_pane *wp;
+ struct format_tree *ft;
- if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
+ 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 = xstrdup(args->argv[0]);
+ cdata->cmd = shellcmd;
cdata->wp_id = wp->id;
cdata->ctx = ctx;
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 0cd7da0bca4..c8cb0b0bb5f 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.333 2013/03/24 09:29:40 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.334 2013/03/24 09:33:35 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -3464,7 +3464,11 @@ Miscellaneous commands are as follows:
.Bl -tag -width Ds
.It Ic clock-mode Op Fl t Ar target-pane
Display a large clock.
-.It Ic if-shell Ar shell-command command Op Ar command
+.It Xo Ic if-shell
+.Op Fl t Ar target-pane
+.Ar shell-command command
+.Op Ar command
+.Xc
.D1 (alias: Ic if )
Execute the first
.Ar command
@@ -3473,6 +3477,10 @@ if
returns success or the second
.Ar command
otherwise.
+Before being executed, shell-command is expanded using the rules specified in the
+.Sx FORMATS
+section, including those relevant to
+.Ar target-pane .
.It Ic lock-server
.D1 (alias: Ic lock )
Lock each client individually by running the command specified by the
@@ -3486,6 +3494,10 @@ option.
Execute
.Ar shell-command
in the background without creating a window.
+Before being executed, shell-command is expanded using the rules specified in
+the
+.Sx FORMATS
+section.
After it finishes, any output to stdout is displayed in copy mode (in the pane
specified by
.Fl t