Fix if-shell and run-shell if there are no sessions. Batted around through

several people, finished off by Chris Johnsen.
This commit is contained in:
Nicholas Marriott 2013-03-11 09:43:56 +00:00
parent 97620bb5be
commit a6ad44f111
2 changed files with 27 additions and 22 deletions

View File

@ -59,18 +59,20 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args; struct args *args = self->args;
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
char *shellcmd; char *shellcmd;
struct session *s; struct session *s = NULL;
struct winlink *wl; struct winlink *wl = NULL;
struct window_pane *wp; struct window_pane *wp = NULL;
struct format_tree *ft; struct format_tree *ft;
if (args_has(args, 't'))
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR);
ft = format_create(); ft = format_create();
if (s != NULL)
format_session(ft, s); format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl); format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp); format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]); shellcmd = format_expand(ft, args->argv[0]);
format_free(ft); format_free(ft);

View File

@ -49,15 +49,16 @@ struct cmd_run_shell_data {
char *cmd; char *cmd;
struct cmd_q *cmdq; struct cmd_q *cmdq;
int bflag; int bflag;
u_int wp_id; int wp_id;
}; };
void void
cmd_run_shell_print(struct job *job, const char *msg) cmd_run_shell_print(struct job *job, const char *msg)
{ {
struct cmd_run_shell_data *cdata = job->data; struct cmd_run_shell_data *cdata = job->data;
struct window_pane *wp; struct window_pane *wp = NULL;
if (cdata->wp_id != -1)
wp = window_pane_find_by_id(cdata->wp_id); wp = window_pane_find_by_id(cdata->wp_id);
if (wp == NULL) { if (wp == NULL) {
cmdq_print(cdata->cmdq, "%s", msg); cmdq_print(cdata->cmdq, "%s", msg);
@ -76,18 +77,20 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args; struct args *args = self->args;
struct cmd_run_shell_data *cdata; struct cmd_run_shell_data *cdata;
char *shellcmd; char *shellcmd;
struct session *s; struct session *s = NULL;
struct winlink *wl; struct winlink *wl = NULL;
struct window_pane *wp; struct window_pane *wp = NULL;
struct format_tree *ft; struct format_tree *ft;
if (args_has(args, 't'))
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp); wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR);
ft = format_create(); ft = format_create();
if (s != NULL)
format_session(ft, s); format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl); format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp); format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]); shellcmd = format_expand(ft, args->argv[0]);
format_free(ft); format_free(ft);
@ -95,7 +98,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd = shellcmd; cdata->cmd = shellcmd;
cdata->bflag = args_has(args, 'b'); cdata->bflag = args_has(args, 'b');
cdata->wp_id = wp->id; cdata->wp_id = wp != NULL ? (int) wp->id : -1;
cdata->cmdq = cmdq; cdata->cmdq = cmdq;
cmdq->references++; cmdq->references++;