summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/session.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2010-09-08 22:02:28 +0000
committernicm <nicm@openbsd.org>2010-09-08 22:02:28 +0000
commite0e6fb95d0fe08c8f5a1d6abaa01bc323cbb96bd (patch)
tree6573c89275326b9c741a728a2eace18884807fe7 /usr.bin/tmux/session.c
parenthad planned to commit the change after oga@ and I are done with little (diff)
downloadwireguard-openbsd-e0e6fb95d0fe08c8f5a1d6abaa01bc323cbb96bd.tar.xz
wireguard-openbsd-e0e6fb95d0fe08c8f5a1d6abaa01bc323cbb96bd.zip
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.c44
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,