From a8c3b02436b5ab098fee49001d948d6ec6271b43 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 22 Feb 2022 11:10:41 +0000 Subject: [PATCH] Add next_session_id format with the next session ID, GitHub issue 3078. --- usr.bin/tmux/format.c | 12 +++++++++++- usr.bin/tmux/session.c | 4 ++-- usr.bin/tmux/tmux.1 | 3 ++- usr.bin/tmux/tmux.h | 3 ++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index ea6cd40844c..2b2a0b70b26 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.299 2021/10/25 21:21:16 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.300 2022/02/22 11:10:41 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -1650,6 +1650,13 @@ format_cb_mouse_y(struct format_tree *ft) return (NULL); } +/* Callback for next_session_id. */ +static void * +format_cb_next_session_id(__unused struct format_tree *ft) +{ + return (format_printf("$%u", next_session_id)); +} + /* Callback for origin_flag. */ static void * format_cb_origin_flag(struct format_tree *ft) @@ -2707,6 +2714,9 @@ static const struct format_table_entry format_table[] = { { "mouse_y", FORMAT_TABLE_STRING, format_cb_mouse_y }, + { "next_session_id", FORMAT_TABLE_STRING, + format_cb_next_session_id + }, { "origin_flag", FORMAT_TABLE_STRING, format_cb_origin_flag }, diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index 4d0b0262889..f710bd75520 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.90 2021/09/17 07:20:49 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.91 2022/02/22 11:10:41 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -29,7 +29,7 @@ #include "tmux.h" struct sessions sessions; -static u_int next_session_id; +u_int next_session_id; struct session_groups session_groups = RB_INITIALIZER(&session_groups); static void session_free(int, short, void *); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 511bd10b8de..9907c5eead5 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.878 2022/02/22 10:53:34 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.879 2022/02/22 11:10:41 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -5098,6 +5098,7 @@ The following variables are available, where appropriate: .It Li "mouse_word" Ta "" Ta "Word under mouse, if any" .It Li "mouse_x" Ta "" Ta "Mouse X position, if any" .It Li "mouse_y" Ta "" Ta "Mouse Y position, if any" +.It Li "next_session_id" Ta "" Ta "Unique session ID for next new session" .It Li "origin_flag" Ta "" Ta "Pane origin flag" .It Li "pane_active" Ta "" Ta "1 if active pane" .It Li "pane_at_bottom" Ta "" Ta "1 if pane is at the bottom of window" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 1822467fcb4..99f541b0133 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1160 2022/02/16 18:55:05 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1161 2022/02/22 11:10:41 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -3118,6 +3118,7 @@ void control_notify_session_window_changed(struct session *); /* session.c */ extern struct sessions sessions; +extern u_int next_session_id; int session_cmp(struct session *, struct session *); RB_PROTOTYPE(sessions, session, entry, session_cmp); int session_alive(struct session *); -- 2.20.1