mirror of
https://github.com/tmux/tmux.git
synced 2024-11-05 02:18:47 +00:00
Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
This commit is contained in:
commit
2ac6501698
2
client.c
2
client.c
@ -270,7 +270,7 @@ client_main(int argc, char **argv, int flags)
|
||||
if (msg == MSG_COMMAND) {
|
||||
/* Fill in command line arguments. */
|
||||
cmddata.pid = environ_pid;
|
||||
cmddata.idx = environ_idx;
|
||||
cmddata.session_id = environ_session_id;
|
||||
|
||||
/* Prepare command for server. */
|
||||
cmddata.argc = argc;
|
||||
|
@ -102,7 +102,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
|
||||
*strchr(tim, '\n') = '\0';
|
||||
|
||||
cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
|
||||
"[flags=0x%x]", s->idx, s->name,
|
||||
"[flags=0x%x]", s->id, s->name,
|
||||
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
|
24
cmd.c
24
cmd.c
@ -122,6 +122,7 @@ struct session *cmd_choose_session(int);
|
||||
struct client *cmd_choose_client(struct clients *);
|
||||
struct client *cmd_lookup_client(const char *);
|
||||
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 *);
|
||||
@ -357,8 +358,8 @@ cmd_current_session(struct cmd_q *cmdq, int prefer_unattached)
|
||||
}
|
||||
|
||||
/* Use the session from the TMUX environment variable. */
|
||||
if (data != NULL && data->pid == getpid() && data->idx != -1) {
|
||||
s = session_find_by_index(data->idx);
|
||||
if (data != NULL && data->pid == getpid() && data->session_id != -1) {
|
||||
s = session_find_by_id(data->session_id);
|
||||
if (s != NULL)
|
||||
return (s);
|
||||
}
|
||||
@ -550,6 +551,21 @@ cmd_lookup_client(const char *name)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Find the target session or report an error and return NULL. */
|
||||
struct session *
|
||||
cmd_lookup_session_id(const char *arg)
|
||||
{
|
||||
char *endptr;
|
||||
long id;
|
||||
|
||||
if (arg[0] != '$')
|
||||
return (NULL);
|
||||
id = strtol(arg + 1, &endptr, 10);
|
||||
if (arg[1] != '\0' && *endptr == '\0')
|
||||
return (session_find_by_id(id));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Lookup a session by name. If no session is found, NULL is returned. */
|
||||
struct session *
|
||||
cmd_lookup_session(const char *name, int *ambiguous)
|
||||
@ -558,6 +574,10 @@ cmd_lookup_session(const char *name, int *ambiguous)
|
||||
|
||||
*ambiguous = 0;
|
||||
|
||||
/* Look for $id first. */
|
||||
if ((s = cmd_lookup_session_id(name)) != NULL)
|
||||
return (s);
|
||||
|
||||
/*
|
||||
* Look for matches. First look for exact matches - session names must
|
||||
* be unique so an exact match can't be ambigious and can just be
|
||||
|
@ -154,7 +154,7 @@ control_notify_attached_session_changed(struct client *c)
|
||||
return;
|
||||
s = c->session;
|
||||
|
||||
control_write(c, "%%session-changed %d %s", s->idx, s->name);
|
||||
control_write(c, "%%session-changed %d %s", s->id, s->name);
|
||||
}
|
||||
|
||||
void
|
||||
|
1
format.c
1
format.c
@ -280,6 +280,7 @@ format_session(struct format_tree *ft, struct session *s)
|
||||
format_add(ft, "session_windows", "%u", winlink_count(&s->windows));
|
||||
format_add(ft, "session_width", "%u", s->sx);
|
||||
format_add(ft, "session_height", "%u", s->sy);
|
||||
format_add(ft, "session_id", "%u", s->id);
|
||||
|
||||
sg = session_group_find(s);
|
||||
format_add(ft, "session_grouped", "%d", sg != NULL);
|
||||
|
@ -273,6 +273,9 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
|
||||
{
|
||||
u_int i, yoff;
|
||||
|
||||
if (!window_pane_visible(wp))
|
||||
return;
|
||||
|
||||
yoff = wp->yoff;
|
||||
if (status_at_line(c) == 0)
|
||||
yoff++;
|
||||
|
@ -39,7 +39,7 @@ server_fill_environ(struct session *s, struct environ *env)
|
||||
term = options_get_string(&s->options, "default-terminal");
|
||||
environ_set(env, "TERM", term);
|
||||
|
||||
idx = s->idx;
|
||||
idx = s->id;
|
||||
} else
|
||||
idx = -1;
|
||||
pid = getpid();
|
||||
|
14
session.c
14
session.c
@ -29,7 +29,7 @@
|
||||
/* Global session list. */
|
||||
struct sessions sessions;
|
||||
struct sessions dead_sessions;
|
||||
u_int next_session;
|
||||
u_int next_session_id;
|
||||
struct session_groups session_groups;
|
||||
|
||||
struct winlink *session_next_alert(struct winlink *);
|
||||
@ -69,14 +69,14 @@ session_find(const char *name)
|
||||
return (RB_FIND(sessions, &sessions, &s));
|
||||
}
|
||||
|
||||
/* Find session by index. */
|
||||
/* Find session by id. */
|
||||
struct session *
|
||||
session_find_by_index(u_int idx)
|
||||
session_find_by_id(u_int id)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
if (s->idx == idx)
|
||||
if (s->id == id)
|
||||
return (s);
|
||||
}
|
||||
return (NULL);
|
||||
@ -120,13 +120,13 @@ session_create(const char *name, const char *cmd, const char *cwd,
|
||||
|
||||
if (name != NULL) {
|
||||
s->name = xstrdup(name);
|
||||
s->idx = next_session++;
|
||||
s->id = next_session_id++;
|
||||
} else {
|
||||
s->name = NULL;
|
||||
do {
|
||||
s->idx = next_session++;
|
||||
s->id = next_session_id++;
|
||||
free (s->name);
|
||||
xasprintf(&s->name, "%u", s->idx);
|
||||
xasprintf(&s->name, "%u", s->id);
|
||||
} while (RB_FIND(sessions, &sessions, s) != NULL);
|
||||
}
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
|
5
tmux.1
5
tmux.1
@ -369,9 +369,9 @@ Clients may be listed with the
|
||||
command.
|
||||
.Pp
|
||||
.Ar target-session
|
||||
is either the name of a session (as listed by the
|
||||
is the session id prefixed with a $, the name of a session (as listed by the
|
||||
.Ic list-sessions
|
||||
command) or the name of a client with the same syntax as
|
||||
command), or the name of a client with the same syntax as
|
||||
.Ar target-client ,
|
||||
in which case the session attached to the client is used.
|
||||
When looking for the session name,
|
||||
@ -3085,6 +3085,7 @@ The following variables are available, where appropriate:
|
||||
.It Li "session_group" Ta "Number of session group"
|
||||
.It Li "session_grouped" Ta "1 if session in a group"
|
||||
.It Li "session_height" Ta "Height of session"
|
||||
.It Li "session_id" Ta "Unique session ID"
|
||||
.It Li "session_name" Ta "Name of session"
|
||||
.It Li "session_width" Ta "Width of session"
|
||||
.It Li "session_windows" Ta "Number of windows in session"
|
||||
|
8
tmux.c
8
tmux.c
@ -48,7 +48,7 @@ char socket_path[MAXPATHLEN];
|
||||
int login_shell;
|
||||
char *environ_path;
|
||||
pid_t environ_pid = -1;
|
||||
int environ_idx = -1;
|
||||
int environ_session_id = -1;
|
||||
|
||||
__dead void usage(void);
|
||||
void parseenvironment(void);
|
||||
@ -147,16 +147,16 @@ parseenvironment(void)
|
||||
{
|
||||
char *env, path[256];
|
||||
long pid;
|
||||
int idx;
|
||||
int id;
|
||||
|
||||
if ((env = getenv("TMUX")) == NULL)
|
||||
return;
|
||||
|
||||
if (sscanf(env, "%255[^,],%ld,%d", path, &pid, &idx) != 3)
|
||||
if (sscanf(env, "%255[^,],%ld,%d", path, &pid, &id) != 3)
|
||||
return;
|
||||
environ_path = xstrdup(path);
|
||||
environ_pid = pid;
|
||||
environ_idx = idx;
|
||||
environ_session_id = id;
|
||||
}
|
||||
|
||||
char *
|
||||
|
10
tmux.h
10
tmux.h
@ -462,8 +462,8 @@ enum msgtype {
|
||||
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
||||
*/
|
||||
struct msg_command_data {
|
||||
pid_t pid; /* PID from $TMUX or -1 */
|
||||
int idx; /* index from $TMUX or -1 */
|
||||
pid_t pid; /* from $TMUX or -1 */
|
||||
int session_id; /* from $TMUX or -1 */
|
||||
|
||||
int argc;
|
||||
char argv[COMMAND_LENGTH];
|
||||
@ -1086,7 +1086,7 @@ struct session_group {
|
||||
TAILQ_HEAD(session_groups, session_group);
|
||||
|
||||
struct session {
|
||||
u_int idx;
|
||||
u_int id;
|
||||
|
||||
char *name;
|
||||
char *cwd;
|
||||
@ -1513,7 +1513,7 @@ extern char socket_path[MAXPATHLEN];
|
||||
extern int login_shell;
|
||||
extern char *environ_path;
|
||||
extern pid_t environ_pid;
|
||||
extern int environ_idx;
|
||||
extern int environ_session_id;
|
||||
void logfile(const char *);
|
||||
const char *getshell(void);
|
||||
int checkshell(const char *);
|
||||
@ -2287,7 +2287,7 @@ int session_cmp(struct session *, struct session *);
|
||||
RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
||||
int session_alive(struct session *);
|
||||
struct session *session_find(const char *);
|
||||
struct session *session_find_by_index(u_int);
|
||||
struct session *session_find_by_id(u_int);
|
||||
struct session *session_create(const char *, const char *, const char *,
|
||||
struct environ *, struct termios *, int, u_int, u_int,
|
||||
char **);
|
||||
|
@ -859,7 +859,7 @@ window_choose_add_session(struct window_pane *wp, struct client *c,
|
||||
struct window_choose_data *wcd;
|
||||
|
||||
wcd = window_choose_data_create(TREE_SESSION, c, c->session);
|
||||
wcd->idx = s->idx;
|
||||
wcd->idx = s->id;
|
||||
|
||||
wcd->tree_session = s;
|
||||
wcd->tree_session->references++;
|
||||
|
Loading…
Reference in New Issue
Block a user