Rename session idx to session id throughout and add $ prefix to targets

to use it, extended from a diff from George Nachman.
pull/1/head
Nicholas Marriott 2013-03-25 10:11:45 +00:00
parent 748acdc77c
commit 6fee3e9e4b
11 changed files with 47 additions and 25 deletions

View File

@ -266,7 +266,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;

View File

@ -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
View File

@ -123,6 +123,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 *);
@ -358,8 +359,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);
}
@ -551,6 +552,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)
@ -559,6 +575,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

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -30,7 +30,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 *);
@ -70,14 +70,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);
@ -121,13 +121,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
View File

@ -365,9 +365,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,
@ -3081,6 +3081,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
View File

@ -49,7 +49,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);
@ -144,16 +144,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
View File

@ -466,8 +466,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];
@ -1090,7 +1090,7 @@ struct session_group {
TAILQ_HEAD(session_groups, session_group);
struct session {
u_int idx;
u_int id;
char *name;
char *cwd;
@ -1517,7 +1517,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 *);
@ -2291,7 +2291,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 **);

View File

@ -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++;