mirror of
https://github.com/tmux/tmux.git
synced 2024-11-05 02:18:47 +00:00
Rename session idx to session id throughout and add $ prefix to targets to use
it, extended from a diff from George Nachman.
This commit is contained in:
parent
bc3580fa06
commit
f47a063841
2
client.c
2
client.c
@ -270,7 +270,7 @@ client_main(int argc, char **argv, int flags)
|
|||||||
if (msg == MSG_COMMAND) {
|
if (msg == MSG_COMMAND) {
|
||||||
/* Fill in command line arguments. */
|
/* Fill in command line arguments. */
|
||||||
cmddata.pid = environ_pid;
|
cmddata.pid = environ_pid;
|
||||||
cmddata.idx = environ_idx;
|
cmddata.session_id = environ_session_id;
|
||||||
|
|
||||||
/* Prepare command for server. */
|
/* Prepare command for server. */
|
||||||
cmddata.argc = argc;
|
cmddata.argc = argc;
|
||||||
|
@ -102,7 +102,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
|
|||||||
*strchr(tim, '\n') = '\0';
|
*strchr(tim, '\n') = '\0';
|
||||||
|
|
||||||
cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
|
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);
|
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
w = wl->window;
|
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_choose_client(struct clients *);
|
||||||
struct client *cmd_lookup_client(const char *);
|
struct client *cmd_lookup_client(const char *);
|
||||||
struct session *cmd_lookup_session(const char *, int *);
|
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 *);
|
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
|
||||||
int cmd_lookup_index(struct session *, const char *, int *);
|
int cmd_lookup_index(struct session *, const char *, int *);
|
||||||
struct window_pane *cmd_lookup_paneid(const char *);
|
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. */
|
/* Use the session from the TMUX environment variable. */
|
||||||
if (data != NULL && data->pid == getpid() && data->idx != -1) {
|
if (data != NULL && data->pid == getpid() && data->session_id != -1) {
|
||||||
s = session_find_by_index(data->idx);
|
s = session_find_by_id(data->session_id);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
@ -550,6 +551,21 @@ cmd_lookup_client(const char *name)
|
|||||||
return (NULL);
|
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. */
|
/* Lookup a session by name. If no session is found, NULL is returned. */
|
||||||
struct session *
|
struct session *
|
||||||
cmd_lookup_session(const char *name, int *ambiguous)
|
cmd_lookup_session(const char *name, int *ambiguous)
|
||||||
@ -558,6 +574,10 @@ cmd_lookup_session(const char *name, int *ambiguous)
|
|||||||
|
|
||||||
*ambiguous = 0;
|
*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
|
* 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
|
* 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;
|
return;
|
||||||
s = c->session;
|
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
|
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_windows", "%u", winlink_count(&s->windows));
|
||||||
format_add(ft, "session_width", "%u", s->sx);
|
format_add(ft, "session_width", "%u", s->sx);
|
||||||
format_add(ft, "session_height", "%u", s->sy);
|
format_add(ft, "session_height", "%u", s->sy);
|
||||||
|
format_add(ft, "session_id", "%u", s->id);
|
||||||
|
|
||||||
sg = session_group_find(s);
|
sg = session_group_find(s);
|
||||||
format_add(ft, "session_grouped", "%d", sg != NULL);
|
format_add(ft, "session_grouped", "%d", sg != NULL);
|
||||||
|
@ -39,7 +39,7 @@ server_fill_environ(struct session *s, struct environ *env)
|
|||||||
term = options_get_string(&s->options, "default-terminal");
|
term = options_get_string(&s->options, "default-terminal");
|
||||||
environ_set(env, "TERM", term);
|
environ_set(env, "TERM", term);
|
||||||
|
|
||||||
idx = s->idx;
|
idx = s->id;
|
||||||
} else
|
} else
|
||||||
idx = -1;
|
idx = -1;
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
|
14
session.c
14
session.c
@ -29,7 +29,7 @@
|
|||||||
/* Global session list. */
|
/* Global session list. */
|
||||||
struct sessions sessions;
|
struct sessions sessions;
|
||||||
struct sessions dead_sessions;
|
struct sessions dead_sessions;
|
||||||
u_int next_session;
|
u_int next_session_id;
|
||||||
struct session_groups session_groups;
|
struct session_groups session_groups;
|
||||||
|
|
||||||
struct winlink *session_next_alert(struct winlink *);
|
struct winlink *session_next_alert(struct winlink *);
|
||||||
@ -69,14 +69,14 @@ session_find(const char *name)
|
|||||||
return (RB_FIND(sessions, &sessions, &s));
|
return (RB_FIND(sessions, &sessions, &s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find session by index. */
|
/* Find session by id. */
|
||||||
struct session *
|
struct session *
|
||||||
session_find_by_index(u_int idx)
|
session_find_by_id(u_int id)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
|
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
if (s->idx == idx)
|
if (s->id == id)
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@ -120,13 +120,13 @@ session_create(const char *name, const char *cmd, const char *cwd,
|
|||||||
|
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
s->name = xstrdup(name);
|
s->name = xstrdup(name);
|
||||||
s->idx = next_session++;
|
s->id = next_session_id++;
|
||||||
} else {
|
} else {
|
||||||
s->name = NULL;
|
s->name = NULL;
|
||||||
do {
|
do {
|
||||||
s->idx = next_session++;
|
s->id = next_session_id++;
|
||||||
free (s->name);
|
free (s->name);
|
||||||
xasprintf(&s->name, "%u", s->idx);
|
xasprintf(&s->name, "%u", s->id);
|
||||||
} while (RB_FIND(sessions, &sessions, s) != NULL);
|
} while (RB_FIND(sessions, &sessions, s) != NULL);
|
||||||
}
|
}
|
||||||
RB_INSERT(sessions, &sessions, s);
|
RB_INSERT(sessions, &sessions, s);
|
||||||
|
5
tmux.1
5
tmux.1
@ -369,9 +369,9 @@ Clients may be listed with the
|
|||||||
command.
|
command.
|
||||||
.Pp
|
.Pp
|
||||||
.Ar target-session
|
.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
|
.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 ,
|
.Ar target-client ,
|
||||||
in which case the session attached to the client is used.
|
in which case the session attached to the client is used.
|
||||||
When looking for the session name,
|
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_group" Ta "Number of session group"
|
||||||
.It Li "session_grouped" Ta "1 if session in a group"
|
.It Li "session_grouped" Ta "1 if session in a group"
|
||||||
.It Li "session_height" Ta "Height of session"
|
.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_name" Ta "Name of session"
|
||||||
.It Li "session_width" Ta "Width of session"
|
.It Li "session_width" Ta "Width of session"
|
||||||
.It Li "session_windows" Ta "Number of windows in 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;
|
int login_shell;
|
||||||
char *environ_path;
|
char *environ_path;
|
||||||
pid_t environ_pid = -1;
|
pid_t environ_pid = -1;
|
||||||
int environ_idx = -1;
|
int environ_session_id = -1;
|
||||||
|
|
||||||
__dead void usage(void);
|
__dead void usage(void);
|
||||||
void parseenvironment(void);
|
void parseenvironment(void);
|
||||||
@ -147,16 +147,16 @@ parseenvironment(void)
|
|||||||
{
|
{
|
||||||
char *env, path[256];
|
char *env, path[256];
|
||||||
long pid;
|
long pid;
|
||||||
int idx;
|
int id;
|
||||||
|
|
||||||
if ((env = getenv("TMUX")) == NULL)
|
if ((env = getenv("TMUX")) == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sscanf(env, "%255[^,],%ld,%d", path, &pid, &idx) != 3)
|
if (sscanf(env, "%255[^,],%ld,%d", path, &pid, &id) != 3)
|
||||||
return;
|
return;
|
||||||
environ_path = xstrdup(path);
|
environ_path = xstrdup(path);
|
||||||
environ_pid = pid;
|
environ_pid = pid;
|
||||||
environ_idx = idx;
|
environ_session_id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
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!
|
* Don't forget to bump PROTOCOL_VERSION if any of these change!
|
||||||
*/
|
*/
|
||||||
struct msg_command_data {
|
struct msg_command_data {
|
||||||
pid_t pid; /* PID from $TMUX or -1 */
|
pid_t pid; /* from $TMUX or -1 */
|
||||||
int idx; /* index from $TMUX or -1 */
|
int session_id; /* from $TMUX or -1 */
|
||||||
|
|
||||||
int argc;
|
int argc;
|
||||||
char argv[COMMAND_LENGTH];
|
char argv[COMMAND_LENGTH];
|
||||||
@ -1086,7 +1086,7 @@ struct session_group {
|
|||||||
TAILQ_HEAD(session_groups, session_group);
|
TAILQ_HEAD(session_groups, session_group);
|
||||||
|
|
||||||
struct session {
|
struct session {
|
||||||
u_int idx;
|
u_int id;
|
||||||
|
|
||||||
char *name;
|
char *name;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
@ -1513,7 +1513,7 @@ extern char socket_path[MAXPATHLEN];
|
|||||||
extern int login_shell;
|
extern int login_shell;
|
||||||
extern char *environ_path;
|
extern char *environ_path;
|
||||||
extern pid_t environ_pid;
|
extern pid_t environ_pid;
|
||||||
extern int environ_idx;
|
extern int environ_session_id;
|
||||||
void logfile(const char *);
|
void logfile(const char *);
|
||||||
const char *getshell(void);
|
const char *getshell(void);
|
||||||
int checkshell(const char *);
|
int checkshell(const char *);
|
||||||
@ -2287,7 +2287,7 @@ int session_cmp(struct session *, struct session *);
|
|||||||
RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
RB_PROTOTYPE(sessions, session, entry, session_cmp);
|
||||||
int session_alive(struct session *);
|
int session_alive(struct session *);
|
||||||
struct session *session_find(const char *);
|
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 session *session_create(const char *, const char *, const char *,
|
||||||
struct environ *, struct termios *, int, u_int, u_int,
|
struct environ *, struct termios *, int, u_int, u_int,
|
||||||
char **);
|
char **);
|
||||||
|
@ -859,7 +859,7 @@ window_choose_add_session(struct window_pane *wp, struct client *c,
|
|||||||
struct window_choose_data *wcd;
|
struct window_choose_data *wcd;
|
||||||
|
|
||||||
wcd = window_choose_data_create(TREE_SESSION, c, c->session);
|
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 = s;
|
||||||
wcd->tree_session->references++;
|
wcd->tree_session->references++;
|
||||||
|
Loading…
Reference in New Issue
Block a user