From: Thomas Adam <tho...@xteddy.org>

While processing the configuration files during server startup,
there may be no sessions (and thus, no panes). If these commands are
used in this context, cmd_find_pane will generate an error message
and the command will abort.

To make these commands usable without a session, skip providing
format data; empty strings will be substituted if format keys are
used.

---

Nicholas hinted that a new release might be coming soon (in a part
of the "monitor" thread), and it seemed important to include
something like this, but it had not yet turned up in the SF git
repository.

So, I thought I would resend a version of Thomas's patch that had
been extended to run-shell (along with the wp_id workaround that
Nicholas indicated would be necessary; though I used UINT_MAX
instead of -1 to avoid having to cast values to/from signed).
---
 cmd-if-shell.c  | 20 +++++++++++---------
 cmd-run-shell.c | 30 ++++++++++++++++++------------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/cmd-if-shell.c b/cmd-if-shell.c
index b921f41..b22e326 100644
--- a/cmd-if-shell.c
+++ b/cmd-if-shell.c
@@ -59,19 +59,21 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
        struct args                     *args = self->args;
        struct cmd_if_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);
 
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index aaa310b..d55b0fe 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -56,9 +56,10 @@ 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 != UINT_MAX)
+               wp = window_pane_find_by_id(cdata->wp_id);
        if (wp == NULL) {
                cmdq_print(cdata->cmdq, "%s", msg);
                return;
@@ -76,26 +77,31 @@ 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;
+       if (wp != NULL)
+               cdata->wp_id = wp->id;
+       else
+               cdata->wp_id = UINT_MAX;
 
        cdata->cmdq = cmdq;
        cmdq->references++;
-- 
1.8.1.3


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to