summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-run-shell.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-25 11:36:42 +0000
committernicm <nicm@openbsd.org>2013-03-25 11:36:42 +0000
commit5be049e65f1f6116af58db8888c9270f89ae5762 (patch)
tree8e24a74597d47b5f5900a04dfc5ce482fff9e6b9 /usr.bin/tmux/cmd-run-shell.c
parentAdd home and end as modified by xterm in keypad mode, from Chris (diff)
downloadwireguard-openbsd-5be049e65f1f6116af58db8888c9270f89ae5762.tar.xz
wireguard-openbsd-5be049e65f1f6116af58db8888c9270f89ae5762.zip
Fix if-shell and run-shell if there are no sessions. Batted around
through several people, finished off by Chris Johnsen.
Diffstat (limited to 'usr.bin/tmux/cmd-run-shell.c')
-rw-r--r--usr.bin/tmux/cmd-run-shell.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c
index bc953d5a42b..6816d730d7d 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.20 2013/03/25 10:03:00 nicm Exp $ */
+/* $OpenBSD: cmd-run-shell.c,v 1.21 2013/03/25 11:36:42 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -49,16 +49,17 @@ struct cmd_run_shell_data {
char *cmd;
struct cmd_q *cmdq;
int bflag;
- u_int wp_id;
+ int wp_id;
};
void
cmd_run_shell_print(struct job *job, const char *msg)
{
struct cmd_run_shell_data *cdata = job->data;
- struct window_pane *wp;
+ struct window_pane *wp = NULL;
- wp = window_pane_find_by_id(cdata->wp_id);
+ if (cdata->wp_id != -1)
+ wp = window_pane_find_by_id(cdata->wp_id);
if (wp == NULL) {
cmdq_print(cdata->cmdq, "%s", msg);
return;
@@ -76,26 +77,28 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
char *shellcmd;
- struct session *s;
- struct winlink *wl;
- struct window_pane *wp;
+ struct session *s = NULL;
+ struct winlink *wl = NULL;
+ struct window_pane *wp = NULL;
struct format_tree *ft;
- wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
- if (wl == NULL)
- return (CMD_RETURN_ERROR);
+ if (args_has(args, 't'))
+ wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
ft = format_create();
- format_session(ft, s);
- format_winlink(ft, s, wl);
- format_window_pane(ft, wp);
+ if (s != NULL)
+ format_session(ft, s);
+ if (s != NULL && wl != NULL)
+ format_winlink(ft, s, wl);
+ if (wp != NULL)
+ format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
cdata = xmalloc(sizeof *cdata);
cdata->cmd = shellcmd;
cdata->bflag = args_has(args, 'b');
- cdata->wp_id = wp->id;
+ cdata->wp_id = wp != NULL ? (int) wp->id : -1;
cdata->cmdq = cmdq;
cmdq->references++;