version 1.72, 2019/05/08 18:05:03 |
version 1.73, 2019/06/12 09:10:29 |
|
|
{ NULL, NULL } |
{ NULL, NULL } |
}; |
}; |
|
|
/* Get session from TMUX if present. */ |
|
static struct session * |
|
cmd_find_try_TMUX(struct client *c) |
|
{ |
|
struct environ_entry *envent; |
|
char tmp[256]; |
|
long long pid; |
|
u_int session; |
|
struct session *s; |
|
|
|
envent = environ_find(c->environ, "TMUX"); |
|
if (envent == NULL) |
|
return (NULL); |
|
|
|
if (sscanf(envent->value, "%255[^,],%lld,%d", tmp, &pid, &session) != 3) |
|
return (NULL); |
|
if (pid != getpid()) |
|
return (NULL); |
|
log_debug("%s: client %p TMUX %s (session $%u)", __func__, c, |
|
envent->value, session); |
|
|
|
s = session_find_by_id(session); |
|
if (s != NULL) |
|
log_debug("%s: session $%u still exists", __func__, s->id); |
|
return (s); |
|
} |
|
|
|
/* Find pane containing client if any. */ |
/* Find pane containing client if any. */ |
static struct window_pane * |
static struct window_pane * |
cmd_find_inside_pane(struct client *c) |
cmd_find_inside_pane(struct client *c) |
{ |
{ |
struct window_pane *wp; |
struct window_pane *wp; |
|
struct environ_entry *envent; |
|
|
if (c == NULL) |
if (c == NULL) |
return (NULL); |
return (NULL); |
|
|
if (wp->fd != -1 && strcmp(wp->tty, c->ttyname) == 0) |
if (wp->fd != -1 && strcmp(wp->tty, c->ttyname) == 0) |
break; |
break; |
} |
} |
|
if (wp == NULL) { |
|
envent = environ_find(c->environ, "TMUX_PANE"); |
|
if (envent != NULL) |
|
wp = window_pane_find_by_id_str(envent->value); |
|
} |
if (wp != NULL) |
if (wp != NULL) |
log_debug("%s: got pane %%%u (%s)", __func__, wp->id, wp->tty); |
log_debug("%s: got pane %%%u (%s)", __func__, wp->id, wp->tty); |
return (wp); |
return (wp); |
|
|
int |
int |
cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags) |
cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags) |
{ |
{ |
struct session *s; |
|
struct winlink *wl; |
|
struct window_pane *wp; |
struct window_pane *wp; |
|
|
/* If no client, treat as from nothing. */ |
/* If no client, treat as from nothing. */ |
|
|
if (wp == NULL) |
if (wp == NULL) |
goto unknown_pane; |
goto unknown_pane; |
|
|
/* If we have a session in TMUX, see if it has this pane. */ |
|
s = cmd_find_try_TMUX(c); |
|
if (s != NULL) { |
|
RB_FOREACH(wl, winlinks, &s->windows) { |
|
if (window_has_pane(wl->window, wp)) |
|
break; |
|
} |
|
if (wl != NULL) { |
|
log_debug("%s: session $%u has pane %%%u", __func__, |
|
s->id, wp->id); |
|
|
|
fs->s = s; |
|
fs->wl = s->curw; /* use current session */ |
|
fs->w = fs->wl->window; |
|
fs->wp = fs->w->active; /* use active pane */ |
|
|
|
cmd_find_log_state(__func__, fs); |
|
return (0); |
|
} else { |
|
log_debug("%s: session $%u does not have pane %%%u", |
|
__func__, s->id, wp->id); |
|
} |
|
} |
|
|
|
/* |
/* |
* Don't have a session, or it doesn't have this pane. Try all |
* Don't have a session, or it doesn't have this pane. Try all |
* sessions. |
* sessions. |
|
|
return (0); |
return (0); |
|
|
unknown_pane: |
unknown_pane: |
/* |
/* We can't find the pane so need to guess. */ |
* We're not running in a known pane, but maybe this client has TMUX |
|
* in the environment. That'd give us a session. |
|
*/ |
|
s = cmd_find_try_TMUX(c); |
|
if (s != NULL) { |
|
cmd_find_from_session(fs, s, flags); |
|
return (0); |
|
} |
|
|
|
/* Otherwise we need to guess. */ |
|
return (cmd_find_from_nothing(fs, flags)); |
return (cmd_find_from_nothing(fs, flags)); |
} |
} |
|
|
|
|
strlcat(tmp, "CANFAIL,", sizeof tmp); |
strlcat(tmp, "CANFAIL,", sizeof tmp); |
if (*tmp != '\0') |
if (*tmp != '\0') |
tmp[strlen(tmp) - 1] = '\0'; |
tmp[strlen(tmp) - 1] = '\0'; |
|
else |
|
strlcat(tmp, "NONE", sizeof tmp); |
log_debug("%s: target %s, type %s, item %p, flags %s", __func__, |
log_debug("%s: target %s, type %s, item %p, flags %s", __func__, |
target == NULL ? "none" : target, s, item, tmp); |
target == NULL ? "none" : target, s, item, tmp); |
|
|