From 39b61e34c1a560d28fe3ec02c96997d6a1b0d92d Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 9 Jan 2014 14:20:55 +0000 Subject: [PATCH] Allow attach-session -t to accept a window and pane to select them on attach. Based on a diff from J Raynor. --- usr.bin/tmux/cmd-attach-session.c | 28 +++++++++++++++++++++++++--- usr.bin/tmux/cmd.c | 4 +--- usr.bin/tmux/tmux.h | 4 +++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c index ae22c0d4e41..2478b19989a 100644 --- a/usr.bin/tmux/cmd-attach-session.c +++ b/usr.bin/tmux/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-attach-session.c,v 1.28 2013/10/10 12:28:08 nicm Exp $ */ +/* $OpenBSD: cmd-attach-session.c,v 1.29 2014/01/09 14:20:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -47,6 +47,9 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, { struct session *s; struct client *c; + struct winlink *wl = NULL; + struct window *w = NULL; + struct window_pane *wp = NULL; const char *update; char *cause; u_int i; @@ -59,12 +62,31 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, return (CMD_RETURN_ERROR); } - if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL) - return (CMD_RETURN_ERROR); + 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 (cmdq->client->session != NULL) { if (dflag) { /* diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 026c5e584c2..4d77dc3aca9 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.89 2013/10/10 12:29:35 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.90 2014/01/09 14:20:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -126,9 +126,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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 8253dda3154..e354faeb86d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.432 2013/10/23 11:31:03 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.433 2014/01/09 14:20:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1739,6 +1739,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; -- 2.20.1