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

Reply via email to