diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-09-08 22:02:29 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2010-09-08 22:02:29 +0000 |
commit | 39668f3cc63395b5572e781e1509f1fda8ed28a8 (patch) | |
tree | 43fac362bfec1658b12d774ebb3794a169475d1b /usr.bin/tmux/session.c | |
parent | 75c27e06b53e680e6c27c18b70bf476861297a71 (diff) |
Add -n and -p flags to switch-client to move to the next and previous
session (yes, it doesn't match window/pane, but so what, nor does
switch-client).
Based on a diff long ago from "edsouza".
Diffstat (limited to 'usr.bin/tmux/session.c')
-rw-r--r-- | usr.bin/tmux/session.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 558e03f773e..c6178c04437 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.19 2010/06/27 02:56:59 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.20 2010/09/08 22:02:28 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -169,6 +169,48 @@ session_index(struct session *s, u_int *i) return (-1); } +/* Find the next usable session. */ +struct session * +session_next_session(struct session *s) +{ + struct session *s2; + u_int i; + + if (ARRAY_LENGTH(&sessions) == 0 || session_index(s, &i) != 0) + return (NULL); + + do { + if (i == ARRAY_LENGTH(&sessions) - 1) + i = 0; + else + i++; + s2 = ARRAY_ITEM(&sessions, i); + } while (s2 == NULL || s2->flags & SESSION_DEAD); + + return (s2); +} + +/* Find the previous usable session. */ +struct session * +session_previous_session(struct session *s) +{ + struct session *s2; + u_int i; + + if (ARRAY_LENGTH(&sessions) == 0 || session_index(s, &i) != 0) + return (NULL); + + do { + if (i == 0) + i = ARRAY_LENGTH(&sessions) - 1; + else + i--; + s2 = ARRAY_ITEM(&sessions, i); + } while (s2 == NULL || s2->flags & SESSION_DEAD); + + return (s2); +} + /* Create a new window on a session. */ struct winlink * session_new(struct session *s, |