summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-03-25 10:11:45 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-03-25 10:11:45 +0000
commit6fee3e9e4b4c68c5d3d7f333c779ac865af7bf86 (patch)
tree9ea9b10bb53304355591a8c1889fd6e2a04519aa
parent748acdc77ca11a09e637324946a6a4f189defc8e (diff)
Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.
-rw-r--r--client.c2
-rw-r--r--cmd-server-info.c2
-rw-r--r--cmd.c24
-rw-r--r--control-notify.c2
-rw-r--r--format.c1
-rw-r--r--server-fn.c2
-rw-r--r--session.c14
-rw-r--r--tmux.15
-rw-r--r--tmux.c8
-rw-r--r--tmux.h10
-rw-r--r--window-choose.c2
11 files changed, 47 insertions, 25 deletions
diff --git a/client.c b/client.c
index 1ab42c51..f3e5dbdc 100644
--- a/client.c
+++ b/client.c
@@ -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;
diff --git a/cmd-server-info.c b/cmd-server-info.c
index a26fe705..07b224a1 100644
--- a/cmd-server-info.c
+++ b/cmd-server-info.c
@@ -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;
diff --git a/cmd.c b/cmd.c
index 33ce730f..83edaf64 100644
--- a/cmd.c
+++ b/cmd.c
@@ -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
diff --git a/control-notify.c b/control-notify.c
index bb9708c8..6bc98b6f 100644
--- a/control-notify.c
+++ b/control-notify.c
@@ -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
diff --git a/format.c b/format.c
index 11f003c8..dc988278 100644
--- a/format.c
+++ b/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);
diff --git a/server-fn.c b/server-fn.c
index 874afffb..f0c2dd23 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -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();
diff --git a/session.c b/session.c
index b1944bc3..c7b54a2b 100644
--- a/session.c
+++ b/session.c
@@ -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);
diff --git a/tmux.1 b/tmux.1
index f6055f11..74868fc2 100644
--- a/tmux.1
+++ b/tmux.1
@@ -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"
diff --git a/tmux.c b/tmux.c
index 7bce10ec..368562f8 100644
--- a/tmux.c
+++ b/tmux.c
@@ -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 *
diff --git a/tmux.h b/tmux.h
index 0da2d0d3..afba7804 100644
--- a/tmux.h
+++ b/tmux.h
@@ -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 **);
diff --git a/window-choose.c b/window-choose.c
index 2671c781..792224c1 100644
--- a/window-choose.c
+++ b/window-choose.c
@@ -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++;