Skip to content

Commit

Permalink
Allow attach-session -t to accept a window and pane to select them on
Browse files Browse the repository at this point in the history
attach. Based on a diff from J Raynor.
  • Loading branch information
nicm committed Jan 9, 2014
1 parent adc1f21 commit 1a0d3cd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
26 changes: 24 additions & 2 deletions cmd-attach-session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
/*
Expand Down
2 changes: 0 additions & 2 deletions cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
2 changes: 2 additions & 0 deletions tmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1a0d3cd

Please sign in to comment.