diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-25 10:11:46 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-25 10:11:46 +0000 |
commit | 3653a2e36a504474dad85bc44af6575646344ad0 (patch) | |
tree | 0c077fe6793f6f13cce816e8d26e2a5fcb047bb0 | |
parent | 26cbfe4a2c044e2f0a503d3695b552de06b31d6d (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-- | usr.bin/tmux/client.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-server-info.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd.c | 26 | ||||
-rw-r--r-- | usr.bin/tmux/control-notify.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/format.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/server-fn.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 7 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 12 | ||||
-rw-r--r-- | usr.bin/tmux/window-choose.c | 4 |
11 files changed, 58 insertions, 36 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index 1f47880a5c5..9083f664b2f 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.63 2013/03/25 10:03:24 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.64 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/cmd-server-info.c b/usr.bin/tmux/cmd-server-info.c index aad3f0cec0b..911164a7750 100644 --- a/usr.bin/tmux/cmd-server-info.c +++ b/usr.bin/tmux/cmd-server-info.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-server-info.c,v 1.32 2013/03/24 09:54:10 nicm Exp $ */ +/* $OpenBSD: cmd-server-info.c,v 1.33 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index 569728a58a8..56fe8893801 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.82 2013/03/25 10:09:05 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.83 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/control-notify.c b/usr.bin/tmux/control-notify.c index 93a8659a453..1a30b1e8239 100644 --- a/usr.bin/tmux/control-notify.c +++ b/usr.bin/tmux/control-notify.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control-notify.c,v 1.3 2013/03/25 10:04:23 nicm Exp $ */ +/* $OpenBSD: control-notify.c,v 1.4 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 9fbfe85296f..46b7271f14b 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.21 2013/03/25 10:07:21 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.22 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/server-fn.c b/usr.bin/tmux/server-fn.c index fcd55b0b311..1a6901541c7 100644 --- a/usr.bin/tmux/server-fn.c +++ b/usr.bin/tmux/server-fn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-fn.c,v 1.66 2013/03/24 09:57:59 nicm Exp $ */ +/* $OpenBSD: server-fn.c,v 1.67 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index c3bd592bb4a..486505b8245 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.37 2013/03/22 16:00:26 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.38 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 7bd4bfafc46..fead7c2ce82 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.343 2013/03/25 10:09:35 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.344 2013/03/25 10:11:45 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -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/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c index 22b2384eaf2..5f2ab2bdb81 100644 --- a/usr.bin/tmux/tmux.c +++ b/usr.bin/tmux/tmux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.c,v 1.115 2013/03/24 09:54:10 nicm Exp $ */ +/* $OpenBSD: tmux.c,v 1.116 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 4893f62730b..40751b9a8d4 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.401 2013/03/25 10:09:07 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.402 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c index 41698b0350e..3f0b446bd73 100644 --- a/usr.bin/tmux/window-choose.c +++ b/usr.bin/tmux/window-choose.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-choose.c,v 1.45 2013/03/24 09:54:10 nicm Exp $ */ +/* $OpenBSD: window-choose.c,v 1.46 2013/03/25 10:11:45 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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++; |