summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-11-27 15:09:36 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-11-27 15:09:36 +0000
commit2339e83e2ae9a132194138fccdd6c58d5192295e (patch)
treee29935bfaada4b2e10d3d173e53f9caaa0d748a2 /usr.bin
parent576d9b861ab07ec98ed76e30ff7f9118682175c6 (diff)
Allow cmd-run-shell to accept -t to specify the pane to display the
output, requested by Alexander Tsepkov.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-run-shell.c47
-rw-r--r--usr.bin/tmux/tmux.112
2 files changed, 46 insertions, 13 deletions
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index a60aa991b0f..9d15e5359bd 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.13 2012/07/11 07:10:15 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.14 2012/11/27 15:09:35 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -30,13 +30,15 @@
*/
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
-void cmd_run_shell_callback(struct job *);
-void cmd_run_shell_free(void *);
+
+void cmd_run_shell_callback(struct job *);
+void cmd_run_shell_free(void *);
+void cmd_run_shell_print(struct job *, const char *);
const struct cmd_entry cmd_run_shell_entry = {
"run-shell", "run",
- "", 1, 1,
- "command",
+ "t:", 1, 1,
+ CMD_TARGET_PANE_USAGE " command",
0,
NULL,
NULL,
@@ -46,17 +48,42 @@ const struct cmd_entry cmd_run_shell_entry = {
struct cmd_run_shell_data {
char *cmd;
struct cmd_ctx ctx;
+ u_int wp_id;
};
+void
+cmd_run_shell_print(struct job *job, const char *msg)
+{
+ struct cmd_run_shell_data *cdata = job->data;
+ struct cmd_ctx *ctx = &cdata->ctx;
+ struct window_pane *wp;
+
+ wp = window_pane_find_by_id(cdata->wp_id);
+ if (wp == NULL) {
+ ctx->print(ctx, "%s", msg);
+ return;
+ }
+
+ if (window_pane_set_mode(wp, &window_copy_mode) == 0)
+ window_copy_init_for_output(wp);
+ if (wp->mode == &window_copy_mode)
+ window_copy_add(wp, "%s", msg);
+}
+
enum cmd_retval
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];
+ struct window_pane *wp;
+
+ if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
+ return (CMD_RETURN_ERROR);
cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]);
+ cdata->wp_id = wp->id;
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
if (ctx->cmdclient != NULL)
@@ -87,7 +114,7 @@ cmd_run_shell_callback(struct job *job)
lines = 0;
do {
if ((line = evbuffer_readline(job->event->input)) != NULL) {
- ctx->print(ctx, "%s", line);
+ cmd_run_shell_print (job, line);
lines++;
}
} while (line != NULL);
@@ -98,7 +125,7 @@ cmd_run_shell_callback(struct job *job)
memcpy(line, EVBUFFER_DATA(job->event->input), size);
line[size] = '\0';
- ctx->print(ctx, "%s", line);
+ cmd_run_shell_print(job, line);
lines++;
free(line);
@@ -115,10 +142,10 @@ cmd_run_shell_callback(struct job *job)
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
}
if (msg != NULL) {
- if (lines != 0)
- ctx->print(ctx, "%s", msg);
- else
+ if (lines == 0)
ctx->info(ctx, "%s", msg);
+ else
+ cmd_run_shell_print(job, msg);
free(msg);
}
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 28e21467737..c497f1a0956 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.307 2012/11/27 13:52:23 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.308 2012/11/27 15:09:35 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -3394,12 +3394,18 @@ otherwise.
Lock each client individually by running the command specified by the
.Ic lock-command
option.
-.It Ic run-shell Ar shell-command
+.It Xo Ic run-shell
+.Op Fl t Ar target-pane
+.Ar shell-command
+.Xc
.D1 (alias: Ic run )
Execute
.Ar shell-command
in the background without creating a window.
-After it finishes, any output to stdout is displayed in copy mode.
+After it finishes, any output to stdout is displayed in copy mode (in the pane
+specified by
+.Fl t
+or the current pane if omitted).
If the command doesn't return success, the exit status is also displayed.
.It Ic server-info
.D1 (alias: Ic info )