From 5e71cf22668c5b0f36906f38bca87dcdbc1aa927 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 13 Jun 2026 08:59:52 +0000 Subject: [PATCH] Change relative time for now to only work in the past and not show a sign which is more useful. Also tidy up some minor style nits. --- usr.bin/tmux/cmd-split-window.c | 9 +++++---- usr.bin/tmux/format.c | 31 ++++++++++++++----------------- usr.bin/tmux/tmux.1 | 8 ++++---- usr.bin/tmux/window-clock.c | 4 ++-- usr.bin/tmux/window-copy.c | 10 +++------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 5606c3a166d..f6a26924f48 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.131 2026/06/10 16:03:14 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.132 2026/06/13 08:59:52 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -190,10 +190,11 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 'k') || args_has(args, 'm')) { options_set_number(new_wp->options, "remain-on-exit", 3); - if (args_has(args, 'm')) + if (args_has(args, 'm')) { options_set_string(new_wp->options, - "remain-on-exit-format", - 0, "%s", args_get(args, 'm')); + "remain-on-exit-format", 0, "%s", + args_get(args, 'm')); + } } if (args_has(args, 'T')) { title = format_single_from_target(item, args_get(args, 'T')); diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 992a0afc7da..62ff151adba 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.374 2026/06/08 21:19:52 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.375 2026/06/13 08:59:52 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott @@ -4052,18 +4052,14 @@ format_relative_time(time_t t) { time_t now, age; u_int d, h, m, s; - char out[32], sign; + char out[32]; time(&now); + if (t > now) + return (NULL); if (t == now) return (xstrdup("0s")); - if (t > now) { - sign = '+'; - age = t - now; - } else { - sign = '-'; - age = now - t; - } + age = now - t; d = age / 86400; h = (age % 86400) / 3600; @@ -4072,21 +4068,21 @@ format_relative_time(time_t t) if (d != 0) { if (h != 0) - xsnprintf(out, sizeof out, "%c%ud%uh", sign, d, h); + xsnprintf(out, sizeof out, "%ud%uh", d, h); else - xsnprintf(out, sizeof out, "%c%ud", sign, d); + xsnprintf(out, sizeof out, "%ud", d); } else if (h != 0) { if (m != 0) - xsnprintf(out, sizeof out, "%c%uh%um", sign, h, m); + xsnprintf(out, sizeof out, "%uh%um", h, m); else - xsnprintf(out, sizeof out, "%c%uh", sign, h); + xsnprintf(out, sizeof out, "%uh", h); } else if (m != 0) { if (s != 0) - xsnprintf(out, sizeof out, "%c%um%us", sign, m, s); + xsnprintf(out, sizeof out, "%um%us", m, s); else - xsnprintf(out, sizeof out, "%c%um", sign, m); + xsnprintf(out, sizeof out, "%um", m); } else - xsnprintf(out, sizeof out, "%c%us", sign, s); + xsnprintf(out, sizeof out, "%us", s); return (xstrdup(out)); } @@ -5183,7 +5179,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen, else if (fm->argc >= 2 && strchr(fm->argv[0], 'f') != NULL) { free(time_format); - time_format = format_strip(es, fm->argv[1]); + time_format = format_strip(es, + fm->argv[1]); } break; case 'q': diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 4fa965b2989..cff73a789bb 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.1080 2026/06/11 10:16:19 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.1081 2026/06/13 08:59:52 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 11 2026 $ +.Dd $Mdocdate: June 13 2026 $ .Dt TMUX 1 .Os .Sh NAME @@ -6410,9 +6410,9 @@ will use shorter but less accurate time format for times in the past. .Ql r .Pq Ql t/r will show the time relative to the current time, for example -.Ql \-1m +.Ql \1m or -.Ql +2m23s . +.Ql 2m23s . A custom format may be given using an .Ql f suffix (note that diff --git a/usr.bin/tmux/window-clock.c b/usr.bin/tmux/window-clock.c index c0fe1a56531..793640289b0 100644 --- a/usr.bin/tmux/window-clock.c +++ b/usr.bin/tmux/window-clock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-clock.c,v 1.32 2026/04/22 07:05:59 nicm Exp $ */ +/* $OpenBSD: window-clock.c,v 1.33 2026/06/13 08:59:52 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -175,7 +175,7 @@ window_clock_init(struct window_mode_entry *wme, struct window_clock_mode_data *data; struct screen *s; - wme->data = data = xmalloc(sizeof *data); + wme->data = data = xcalloc(1, sizeof *data); data->tim = time(NULL); evtimer_set(&data->timer, window_clock_timer_callback, wme); diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 818e07bc684..9b7c0417f01 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.404 2026/06/10 14:29:08 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.405 2026/06/13 08:59:52 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -5102,14 +5102,10 @@ window_copy_set_line_numbers(struct window_pane *wp, int enabled) struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); struct window_copy_mode_data *data; - if (wme == NULL) - return; - if (wme->mode != &window_copy_mode) + if (wme == NULL || wme->mode != &window_copy_mode) return; data = wme->data; - if (data == NULL) - return; - if (data->line_numbers == enabled) + if (data == NULL || data->line_numbers == enabled) return; data->line_numbers = enabled; window_copy_redraw_screen(wme);