summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-08-13 20:11:59 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-08-13 20:11:59 +0000
commitabd8dc826b9d937883e427da430db819c48a0beb (patch)
tree6953f0889ff5b520cb42555f48e63d92b9f67eb1 /usr.bin/tmux
parentc8449b498e622646c2abe191cb151dc23a2d0893 (diff)
Add a base-index session option to specify the first index checked when looking
for an index for a new window.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-break-pane.c6
-rw-r--r--usr.bin/tmux/cmd-link-window.c4
-rw-r--r--usr.bin/tmux/cmd-move-window.c4
-rw-r--r--usr.bin/tmux/cmd-new-session.c8
-rw-r--r--usr.bin/tmux/cmd-new-window.c4
-rw-r--r--usr.bin/tmux/cmd-set-option.c3
-rw-r--r--usr.bin/tmux/session.c9
-rw-r--r--usr.bin/tmux/tmux.16
-rw-r--r--usr.bin/tmux/tmux.c3
-rw-r--r--usr.bin/tmux/tmux.h7
-rw-r--r--usr.bin/tmux/window.c28
11 files changed, 51 insertions, 31 deletions
diff --git a/usr.bin/tmux/cmd-break-pane.c b/usr.bin/tmux/cmd-break-pane.c
index af754f5ddc7..8a24d275847 100644
--- a/usr.bin/tmux/cmd-break-pane.c
+++ b/usr.bin/tmux/cmd-break-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-break-pane.c,v 1.5 2009/07/30 13:45:56 nicm Exp $ */
+/* $OpenBSD: cmd-break-pane.c,v 1.6 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,6 +48,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window_pane *wp;
struct window *w;
char *cause;
+ int base_idx;
if ((wl = cmd_find_pane(ctx, data->target, &s, &wp)) == NULL)
return (-1);
@@ -71,7 +72,8 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->name = default_window_name(w);
layout_init(w);
- wl = session_attach(s, w, -1, &cause); /* can't fail */
+ base_idx = options_get_number(&s->options, "base-index");
+ wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
if (!(data->chflags & CMD_CHFLAG('d')))
session_select(s, wl->idx);
diff --git a/usr.bin/tmux/cmd-link-window.c b/usr.bin/tmux/cmd-link-window.c
index 53f413b99ca..67f10605824 100644
--- a/usr.bin/tmux/cmd-link-window.c
+++ b/usr.bin/tmux/cmd-link-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-link-window.c,v 1.4 2009/07/26 12:58:44 nicm Exp $ */
+/* $OpenBSD: cmd-link-window.c,v 1.5 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -77,6 +77,8 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
+ if (idx == -1)
+ idx = -1 - options_get_number(&dst->options, "base-index");
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
if (wl_dst == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
diff --git a/usr.bin/tmux/cmd-move-window.c b/usr.bin/tmux/cmd-move-window.c
index a7301d94d1b..c4e6cf3ea57 100644
--- a/usr.bin/tmux/cmd-move-window.c
+++ b/usr.bin/tmux/cmd-move-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-move-window.c,v 1.4 2009/07/26 12:58:44 nicm Exp $ */
+/* $OpenBSD: cmd-move-window.c,v 1.5 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -79,6 +79,8 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
+ if (idx == -1)
+ idx = -1 - options_get_number(&dst->options, "base-index");
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
if (wl_dst == NULL) {
ctx->error(ctx, "attach window failed: %s", cause);
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 8cdc064345f..f0bfd99aec0 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.12 2009/08/13 19:16:14 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.13 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -118,7 +118,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct termios tio;
const char *update;
char *overrides, *cmd, *cwd, *cause;
- int detached;
+ int detached, idx;
u_int sx, sy;
if (data->newname != NULL && session_find(data->newname) != NULL) {
@@ -216,7 +216,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
tio.c_ospeed = TTYDEF_SPEED;
/* Create the new session. */
- s = session_create(data->newname, cmd, cwd, &env, &tio, sx, sy, &cause);
+ idx = -1 - options_get_number(&global_s_options, "base-index");
+ s = session_create(
+ data->newname, cmd, cwd, &env, &tio, idx, sx, sy, &cause);
if (s == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
xfree(cause);
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index fd55516f7c6..b59220a38e6 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.5 2009/07/26 12:58:44 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.6 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -154,6 +154,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
else
cwd = ctx->cmdclient->cwd;
+ if (idx == -1)
+ idx = -1 - options_get_number(&s->options, "base-index");
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
if (wl == NULL) {
ctx->error(ctx, "create window failed: %s", cause);
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c
index 9dd72809f3e..965cd622140 100644
--- a/usr.bin/tmux/cmd-set-option.c
+++ b/usr.bin/tmux/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-set-option.c,v 1.14 2009/08/11 12:53:37 nicm Exp $ */
+/* $OpenBSD: cmd-set-option.c,v 1.15 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -50,6 +50,7 @@ const char *set_option_bell_action_list[] = {
"none", "any", "current", NULL
};
const struct set_option_entry set_option_table[] = {
+ { "base-index", SET_OPTION_NUMBER, 0, INT_MAX, NULL },
{ "bell-action", SET_OPTION_CHOICE, 0, 0, set_option_bell_action_list },
{ "buffer-limit", SET_OPTION_NUMBER, 1, INT_MAX, NULL },
{ "default-command", SET_OPTION_STRING, 0, 0, NULL },
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index af7ea96e047..21f9dcfdb89 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.4 2009/08/13 19:04:00 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.5 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -113,7 +113,8 @@ session_find(const char *name)
/* Create a new session. */
struct session *
session_create(const char *name, const char *cmd, const char *cwd,
- struct environ *env, struct termios *tio, u_int sx, u_int sy, char **cause)
+ struct environ *env, struct termios *tio, int idx, u_int sx, u_int sy,
+ char **cause)
{
struct session *s;
u_int i;
@@ -149,11 +150,11 @@ session_create(const char *name, const char *cmd, const char *cwd,
s->name = xstrdup(name);
else
xasprintf(&s->name, "%u", i);
- if (session_new(s, NULL, cmd, cwd, -1, cause) == NULL) {
+ if (session_new(s, NULL, cmd, cwd, idx, cause) == NULL) {
session_destroy(s);
return (NULL);
}
- session_select(s, 0);
+ session_select(s, RB_ROOT(&s->windows)->idx);
log_debug("session %s created", s->name);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index d1fe7ebcb1d..f83e4e51ab0 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.68 2009/08/13 19:04:00 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.69 2009/08/13 20:11:58 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -1064,6 +1064,10 @@ options - it is not possible to unset a global option.
.Pp
Available session options are:
.Bl -tag -width Ds
+.It Ic base-index Ar index
+Set the base index from which an unused index should be searched when a new
+window is created.
+The default is zero.
.It Xo Ic bell-action
.Op Ic any | none | current
.Xc
diff --git a/usr.bin/tmux/tmux.c b/usr.bin/tmux/tmux.c
index 6fc6028e299..87b1e197e94 100644
--- a/usr.bin/tmux/tmux.c
+++ b/usr.bin/tmux/tmux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.c,v 1.32 2009/08/12 09:14:25 nicm Exp $ */
+/* $OpenBSD: tmux.c,v 1.33 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -342,6 +342,7 @@ main(int argc, char **argv)
}
options_init(&global_s_options, NULL);
+ options_set_number(&global_s_options, "base-index", 0);
options_set_number(&global_s_options, "bell-action", BELL_ANY);
options_set_number(&global_s_options, "buffer-limit", 9);
options_set_string(&global_s_options, "default-command", "%s", "");
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index f99fa73e94c..9776a5b3dbd 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.80 2009/08/13 19:04:00 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.81 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1565,7 +1565,7 @@ RB_PROTOTYPE(windows, window, entry, window_cmp);
RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
struct winlink *winlink_find_by_index(struct winlinks *, int);
struct winlink *winlink_find_by_window(struct winlinks *, struct window *);
-int winlink_next_index(struct winlinks *);
+int winlink_next_index(struct winlinks *, int);
u_int winlink_count(struct winlinks *);
struct winlink *winlink_add(struct winlinks *, struct window *, int);
void winlink_remove(struct winlinks *, struct winlink *);
@@ -1670,7 +1670,8 @@ int session_alert_has(struct session *, struct winlink *, int);
int session_alert_has_window(struct session *, struct window *, int);
struct session *session_find(const char *);
struct session *session_create(const char *, const char *, const char *,
- struct environ *, struct termios *, u_int, u_int, char **);
+ struct environ *, struct termios *, int, u_int, u_int,
+ char **);
void session_destroy(struct session *);
int session_index(struct session *, u_int *);
struct winlink *session_new(struct session *,
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index d163dbb0c4b..e6809ebea7f 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.21 2009/08/13 19:04:00 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.22 2009/08/13 20:11:58 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -122,16 +122,20 @@ winlink_find_by_index(struct winlinks *wwl, int idx)
}
int
-winlink_next_index(struct winlinks *wwl)
+winlink_next_index(struct winlinks *wwl, int idx)
{
- u_int i;
+ int i;
- for (i = 0; i < INT_MAX; i++) {
+ i = idx;
+ do {
if (winlink_find_by_index(wwl, i) == NULL)
return (i);
- }
-
- fatalx("no free indexes");
+ if (i == INT_MAX)
+ i = 0;
+ else
+ i++;
+ } while (i != idx);
+ return (-1);
}
u_int
@@ -152,14 +156,12 @@ winlink_add(struct winlinks *wwl, struct window *w, int idx)
{
struct winlink *wl;
- if (idx == -1)
- idx = winlink_next_index(wwl);
- else if (winlink_find_by_index(wwl, idx) != NULL)
+ if (idx < 0) {
+ if ((idx = winlink_next_index(wwl, -idx - 1)) == -1)
+ return (NULL);
+ } else if (winlink_find_by_index(wwl, idx) != NULL)
return (NULL);
- if (idx < 0)
- fatalx("bad index");
-
wl = xcalloc(1, sizeof *wl);
wl->idx = idx;
wl->window = w;