Add t/d for time difference in seconds.

This commit is contained in:
nicm
2026-07-09 06:33:19 +00:00
parent e37a2e54ab
commit 1fefb80445
2 changed files with 21 additions and 1 deletions

View File

@@ -127,6 +127,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_QUOTE_SHELL_SQ 0x20000000
#define FORMAT_OPTIONS 0x40000000
#define FORMAT_ENVIRON 0x80000000ULL
#define FORMAT_DIFFERENCE 0x100000000ULL
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 100
@@ -4203,6 +4204,17 @@ format_relative_time(time_t t)
return (xstrdup(out));
}
/* Make a time difference in seconds. */
static char *
format_time_difference(time_t t)
{
time_t now = time(NULL);
char *out;
xasprintf(&out, "%ld", (long)now - (long)t);
return (out);
}
/* Find a format entry. */
static char *
format_find(struct format_tree *ft, const char *key, uint64_t modifiers,
@@ -4287,6 +4299,8 @@ found:
return (NULL);
if (modifiers & FORMAT_RELATIVE)
found = format_relative_time(t);
else if (modifiers & FORMAT_DIFFERENCE)
found = format_time_difference(t);
else if (modifiers & FORMAT_PRETTY)
found = format_pretty_time(t, 0);
else {
@@ -5666,6 +5680,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
modifiers |= FORMAT_PRETTY;
else if (strchr(fm->argv[0], 'r') != NULL)
modifiers |= FORMAT_RELATIVE;
else if (strchr(fm->argv[0], 'd') != NULL)
modifiers |= FORMAT_DIFFERENCE;
else if (fm->argc >= 2 &&
strchr(fm->argv[0], 'f') != NULL) {
free(time_format);

6
tmux.1
View File

@@ -6813,10 +6813,14 @@ Adding
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
will give the time relative to the current time, for example
.Ql \&1m
or
.Ql 2m23s .
.Ql d
.Pq Ql t/d
will give the difference from the time to current time in seconds (future
times are negative).
A custom format may be given using an
.Ql f
suffix (note that