Made a change (more like copy-paste) to conform with attach and it seems to 
work fine.
Also attached as a file.

From 0b2298d447d5409952d705eed5a7253947fe4c81 Mon Sep 17 00:00:00 2001
From: Johannes Jakobsson <johannes.jakobs...@gmail.com>
Date: Tue, 10 Dec 2013 20:43:51 +0100
Subject: [PATCH] switch-client now conforms to '-t session:win.pane'

---
 cmd-switch-client.c | 41 ++++++++++++++++++++++++++++++++++-------
 cmd.c               |  2 --
 tmux.h              |  2 ++
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index d101c52..e97e3f8 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -60,8 +60,13 @@ enum cmd_retval
 cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
 {
        struct args     *args = self->args;
-       struct client   *c;
-       struct session  *s;
+       struct client   *c = NULL;
+       struct session  *s = NULL;
+       struct winlink *wl = NULL;
+       struct window_pane *wp = NULL;
+       struct window *w = NULL;
+
+       const char *tflag = NULL;
 
        if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
                return (CMD_RETURN_ERROR);
@@ -76,7 +81,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
                }
        }
 
-       s = NULL;
+       tflag = args_get(args, 't');
        if (args_has(args, 'n')) {
                if ((s = session_next_session(c->session)) == NULL) {
                        cmdq_error(cmdq, "can't find next session");
@@ -94,10 +99,32 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
                        cmdq_error(cmdq, "can't find last session");
                        return (CMD_RETURN_ERROR);
                }
-       } else
-               s = cmd_find_session(cmdq, args_get(args, 't'), 0);
-       if (s == NULL)
-               return (CMD_RETURN_ERROR);
+       } else {
+               if (tflag == NULL) {
+                       if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
+                               return (CMD_RETURN_ERROR);
+               } else if (tflag[strcspn(tflag, ":.")] != '\0') {
+                       if ((wl = cmd_find_pane(cmdq, tflag, &s, &wp)) == NULL)
+                               return (CMD_RETURN_ERROR);
+               } else {
+                       if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
+                               return (CMD_RETURN_ERROR);
+                       w = cmd_lookup_windowid(tflag);
+                       if (w == NULL && (wp = cmd_lookup_paneid(tflag)) != 
NULL)
+                               w = wp->window;
+                       if (w != NULL)
+                               wl = winlink_find_by_window(&s->windows, w);
+               }
+
+               if (cmdq->client == NULL)
+                       return (CMD_RETURN_NORMAL);
+
+               if (wl != NULL) {
+                       if (wp != NULL)
+                               window_set_active_pane(wp->window, wp);
+                       session_set_current(s, wl);
+               }
+       }
 
        if (c->session != NULL)
                c->last_session = c->session;
diff --git a/cmd.c b/cmd.c
index 414c906..5e6b93a 100644
--- a/cmd.c
+++ b/cmd.c
@@ -125,9 +125,7 @@ struct session      *cmd_lookup_session(const char *, int 
*);
 struct session *cmd_lookup_session_id(const char *);
 struct winlink *cmd_lookup_window(struct session *, const char *, int *);
 int             cmd_lookup_index(struct session *, const char *, int *);
-struct window_pane *cmd_lookup_paneid(const char *);
 struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *);
-struct window  *cmd_lookup_windowid(const char *);
 struct session *cmd_window_session(struct cmd_q *, struct window *,
                    struct winlink **);
 struct winlink *cmd_find_window_offset(const char *, struct session *, int *);
diff --git a/tmux.h b/tmux.h
index dbc2c49..9c83892 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1732,6 +1732,8 @@ int                cmd_find_index(struct cmd_q *, const 
char *,
 struct winlink *cmd_find_pane(struct cmd_q *, const char *, struct session **,
                     struct window_pane **);
 char           *cmd_template_replace(const char *, const char *, int);
+struct window  *cmd_lookup_windowid(const char *);
+struct window_pane *cmd_lookup_paneid(const char *);
 extern const struct cmd_entry *cmd_table[];
 extern const struct cmd_entry cmd_attach_session_entry;
 extern const struct cmd_entry cmd_bind_key_entry;
-- 
1.8.3.2


Attachment: switch-client.patch
Description: Binary data

On 10 12, 2013, at 18:32 , Johannes Jakobsson <johannes.jakobs...@gmail.com> 
wrote:

> I take it that it is the “-t session:window.pane” syntax you would prefer? I 
> will make a new patch with that change.
> 
> On 10 12, 2013, at 16:49 , Nicholas Marriott <nicholas.marri...@gmail.com> 
> wrote:
> 
>> Thanks but I don't like this way of doing it.
>> 
>> I think this should work the same way as attach-session.
>> 
>> Take a look at the mail I just sent in the thread subject "patch
>> allowing attach to take and select a pane".
>> 
>> Both attach and switchc should work the same way, probably the way
>> suggested in that thread.
>> 
>> The alternative is that -w or -p or some other flag indicates -t is a
>> window or pane rather than a session, but this isn't as nice for the
>> user.
>> 
>> 
>> On Sun, Dec 08, 2013 at 11:25:57AM +0100, Johannes Jakobsson wrote:
>>> Add [-w window] to switch-client to specify which window in the 
>>> target-session to switch to.
>>> 
>>> //Johannes
>>> 
>>>> From d8efa53ec1104db86f4fd75be5a59d2317e7b673 Mon Sep 17 00:00:00 2001
>>> From: Johannes Jakobsson <johannes.jakobs...@gmail.com>
>>> Date: Sat, 7 Dec 2013 16:57:01 +0100
>>> Subject: [PATCH] '-w' option to switch-client
>>> 
>>> Example: switch-client -t s1 -w w1
>>> ---
>>> cmd-switch-client.c | 22 ++++++++++++++++++++--
>>> 1 file changed, 20 insertions(+), 2 deletions(-)
>>> 
>>> diff --git a/cmd-switch-client.c b/cmd-switch-client.c
>>> index d101c52..68045c8 100644
>>> --- a/cmd-switch-client.c
>>> +++ b/cmd-switch-client.c
>>> @@ -32,8 +32,8 @@ enum cmd_retval    cmd_switch_client_exec(struct cmd *, 
>>> struct cmd_q *);
>>> 
>>> const struct cmd_entry cmd_switch_client_entry = {
>>>     "switch-client", "switchc",
>>> -   "lc:npt:r", 0, 0,
>>> -   "[-lnpr] [-c target-client] [-t target-session]",
>>> +   "lc:npt:rw:", 0, 0,
>>> +   "[-lnpr] [-c target-client] [-t target-session] [-w window]",
>>>     CMD_READONLY,
>>>     cmd_switch_client_key_binding,
>>>     cmd_switch_client_exec
>>> @@ -62,6 +62,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q 
>>> *cmdq)
>>>     struct args     *args = self->args;
>>>     struct client   *c;
>>>     struct session  *s;
>>> +  struct winlink *wl;
>>> 
>>>     if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
>>>             return (CMD_RETURN_ERROR);
>>> @@ -99,6 +100,23 @@ cmd_switch_client_exec(struct cmd *self, struct cmd_q 
>>> *cmdq)
>>>     if (s == NULL)
>>>             return (CMD_RETURN_ERROR);
>>> 
>>> +  wl = NULL;
>>> +  if (args_has(args, 'w')) {
>>> +    /* Prepend the choosen session name in front of the
>>> +     * window name to make cmd_find_window work.
>>> +     */
>>> +    char *sw;
>>> +    const char *w_name = args_get(args, 'w');
>>> +    xasprintf(&sw, "%s:%s", s->name, w_name);
>>> +    wl = cmd_find_window(cmdq, sw, &s);
>>> +    free(sw);
>>> +    if (wl == NULL) {
>>> +                   cmdq_error(cmdq, "can't find window");
>>> +                   return (CMD_RETURN_ERROR);
>>> +    }
>>> +    session_set_current(s, wl);
>>> +  }
>>> +
>>>     if (c->session != NULL)
>>>             c->last_session = c->session;
>>>     c->session = s;
>>> -- 
>>> 1.8.3.2
>>> 
>>> 
>>> ------------------------------------------------------------------------------
>>> Sponsored by Intel(R) XDK 
>>> Develop, test and display web and hybrid apps with a single code base.
>>> Download it for free now!
>>> http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
>>> _______________________________________________
>>> tmux-users mailing list
>>> tmux-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/tmux-users
> 

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to