From 1416ceb57589ba119a36d9f32d919d3444f7b0d0 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 14 Mar 2019 21:27:26 +0000 Subject: Accept 0 time as a shorthand for now to format_expand_time. --- cmd-display-message.c | 2 +- cmd-pipe-pane.c | 2 +- format.c | 2 ++ server-client.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd-display-message.c b/cmd-display-message.c index 5856e2d8..6dd210ac 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -86,7 +86,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) ft = format_create(item->client, item, FORMAT_NONE, 0); format_defaults(ft, target_c, s, wl, wp); - msg = format_expand_time(ft, template, time(NULL)); + msg = format_expand_time(ft, template, 0); if (args_has(self->args, 'p')) cmdq_print(item, "%s", msg); else if (c != NULL) diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index e1bdb82d..c0d2939f 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -110,7 +110,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item) /* Expand the command. */ ft = format_create(item->client, item, FORMAT_NONE, 0); format_defaults(ft, c, s, wl, wp); - cmd = format_expand_time(ft, args->argv[0], time(NULL)); + cmd = format_expand_time(ft, args->argv[0], 0); format_free(ft); /* Fork the child. */ diff --git a/format.c b/format.c index ae3086d1..6f042f8a 100644 --- a/format.c +++ b/format.c @@ -1482,6 +1482,8 @@ format_expand_time(struct format_tree *ft, const char *fmt, time_t t) if (fmt == NULL || *fmt == '\0') return (xstrdup("")); + if (t == 0) + t = time(NULL); tm = localtime(&t); if (strftime(s, sizeof s, fmt, tm) == 0) diff --git a/server-client.c b/server-client.c index b7d052a0..5bd77c84 100644 --- a/server-client.c +++ b/server-client.c @@ -1537,7 +1537,7 @@ server_client_set_title(struct client *c) ft = format_create(c, NULL, FORMAT_NONE, 0); format_defaults(ft, c, NULL, NULL, NULL); - title = format_expand_time(ft, template, time(NULL)); + title = format_expand_time(ft, template, 0); if (c->title == NULL || strcmp(title, c->title) != 0) { free(c->title); c->title = xstrdup(title); -- cgit From 38064e759342b38fbeea48ea716b7d29679271b1 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 14 Mar 2019 21:31:43 +0000 Subject: Add T format modifier like E but also do strftime(3). --- format.c | 19 ++++++++++++++----- tmux.1 | 6 ++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/format.c b/format.c index 6f042f8a..530e2403 100644 --- a/format.c +++ b/format.c @@ -95,9 +95,10 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2) #define FORMAT_QUOTE 0x8 #define FORMAT_LITERAL 0x10 #define FORMAT_EXPAND 0x20 -#define FORMAT_SESSIONS 0x40 -#define FORMAT_WINDOWS 0x80 -#define FORMAT_PANES 0x100 +#define FORMAT_EXPANDTIME 0x40 +#define FORMAT_SESSIONS 0x80 +#define FORMAT_WINDOWS 0x100 +#define FORMAT_PANES 0x200 /* Entry in format tree. */ struct format_entry { @@ -1001,7 +1002,7 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count) /* * Modifiers are a ; separated list of the forms: - * l,m,C,b,d,t,q + * l,m,C,b,d,t,q,E,T,S,W,P * =a * =/a * =/a/ @@ -1018,7 +1019,7 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count) cp++; /* Check single character modifiers with no arguments. */ - if (strchr("lmCbdtqESWP", cp[0]) != NULL && + if (strchr("lmCbdtqETSWP", cp[0]) != NULL && format_is_end(cp[1])) { format_add_modifier(&list, count, cp, 1, NULL, 0); cp++; @@ -1305,6 +1306,9 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, case 'E': modifiers |= FORMAT_EXPAND; break; + case 'T': + modifiers |= FORMAT_EXPANDTIME; + break; case 'S': modifiers |= FORMAT_SESSIONS; break; @@ -1432,6 +1436,11 @@ done: free(value); value = new; } + else if (modifiers & FORMAT_EXPANDTIME) { + new = format_expand_time(ft, value, 0); + free(value); + value = new; + } /* Perform substitution if any. */ if (sub != NULL) { diff --git a/tmux.1 b/tmux.1 index 49e82643..12da91ec 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3719,6 +3719,12 @@ will expand the format twice, for example is the result of expanding the content of the .Ic status-left option rather than the content itself. +.Ql T: +is like +.Ql E: +but also expands +.Xr strftime 3 +specifiers. .Ql S: , .Ql W: or -- cgit