From 01831da5f5dd2a1b7622ad421a757cacedbdfc59 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 11 Dec 2015 12:27:36 +0000 Subject: [PATCH] Add cmdq as an argument to format_create and add a format for the command name (will also be used for more later). --- cmd-attach-session.c | 2 +- cmd-break-pane.c | 2 +- cmd-display-message.c | 2 +- cmd-if-shell.c | 2 +- cmd-list-buffers.c | 2 +- cmd-list-clients.c | 2 +- cmd-list-panes.c | 2 +- cmd-list-sessions.c | 2 +- cmd-list-windows.c | 2 +- cmd-new-session.c | 4 ++-- cmd-new-window.c | 4 ++-- cmd-pipe-pane.c | 2 +- cmd-run-shell.c | 2 +- cmd-split-window.c | 4 ++-- control-notify.c | 2 +- format.c | 5 ++++- names.c | 2 +- server-client.c | 2 +- status.c | 8 ++++---- tmux.1 | 1 + tmux.h | 2 +- window-choose.c | 2 +- window-copy.c | 2 +- 23 files changed, 32 insertions(+), 28 deletions(-) diff --git a/cmd-attach-session.c b/cmd-attach-session.c index dd953ebd..73c82248 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -93,7 +93,7 @@ cmd_attach_session(struct cmd_q *cmdq, const char *tflag, int dflag, int rflag, } if (cflag != NULL) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); cwd = format_expand(ft, cflag); diff --git a/cmd-break-pane.c b/cmd-break-pane.c index 75ae9044..98d6ad3d 100644 --- a/cmd-break-pane.c +++ b/cmd-break-pane.c @@ -101,7 +101,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = BREAK_PANE_TEMPLATE; - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), dst_s, wl, wp); diff --git a/cmd-display-message.c b/cmd-display-message.c index 2fb76caa..7ca8e9c4 100644 --- a/cmd-display-message.c +++ b/cmd-display-message.c @@ -88,7 +88,7 @@ cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq) if (template == NULL) template = DISPLAY_MESSAGE_TEMPLATE; - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, c, s, wl, wp); msg = format_expand_time(ft, template, time(NULL)); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index 9907a764..3345e8ce 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -86,7 +86,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq) cwd = NULL; } - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, NULL, s, wl, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); diff --git a/cmd-list-buffers.c b/cmd-list-buffers.c index a95cc336..218eb6ff 100644 --- a/cmd-list-buffers.c +++ b/cmd-list-buffers.c @@ -54,7 +54,7 @@ cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq) pb = NULL; while ((pb = paste_walk(pb)) != NULL) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults_paste_buffer(ft, pb); line = format_expand(ft, template); diff --git a/cmd-list-clients.c b/cmd-list-clients.c index 2bde6b32..2c13d398 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -69,7 +69,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq) if (c->session == NULL || (s != NULL && s != c->session)) continue; - ft = format_create(0); + ft = format_create(cmdq, 0); format_add(ft, "line", "%u", idx); format_defaults(ft, c, NULL, NULL, NULL); diff --git a/cmd-list-panes.c b/cmd-list-panes.c index 14ee7064..23e530e2 100644 --- a/cmd-list-panes.c +++ b/cmd-list-panes.c @@ -125,7 +125,7 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl, n = 0; TAILQ_FOREACH(wp, &wl->window->panes, entry) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, wp); diff --git a/cmd-list-sessions.c b/cmd-list-sessions.c index 099b4f2e..fed0c2ee 100644 --- a/cmd-list-sessions.c +++ b/cmd-list-sessions.c @@ -61,7 +61,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq) n = 0; RB_FOREACH(s, sessions, &sessions) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, NULL, NULL); diff --git a/cmd-list-windows.c b/cmd-list-windows.c index 958380e2..81793e10 100644 --- a/cmd-list-windows.c +++ b/cmd-list-windows.c @@ -105,7 +105,7 @@ cmd_list_windows_session( n = 0; RB_FOREACH(wl, winlinks, &s->windows) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_add(ft, "line", "%u", n); format_defaults(ft, NULL, s, wl, NULL); diff --git a/cmd-new-session.c b/cmd-new-session.c index 52e24ae6..aee69e12 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -119,7 +119,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) /* Get the new session working directory. */ to_free = NULL; if (args_has(args, 'c')) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL, NULL); to_free = cwd = format_expand(ft, args_get(args, 'c')); @@ -283,7 +283,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = NEW_SESSION_TEMPLATE; - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); diff --git a/cmd-new-window.c b/cmd-new-window.c index 0865a9bc..ddfd6a20 100644 --- a/cmd-new-window.c +++ b/cmd-new-window.c @@ -94,7 +94,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) to_free = NULL; if (args_has(args, 'c')) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); cwd = to_free = format_expand(ft, args_get(args, 'c')); @@ -143,7 +143,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = NEW_WINDOW_TEMPLATE; - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl, NULL); diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index 1577c252..79ef7818 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -89,7 +89,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) } /* Expand the command. */ - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, c, s, wl, wp); cmd = format_expand_time(ft, args->argv[0], time(NULL)); format_free(ft); diff --git a/cmd-run-shell.c b/cmd-run-shell.c index a381fb91..fd5d84d4 100644 --- a/cmd-run-shell.c +++ b/cmd-run-shell.c @@ -100,7 +100,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq) cwd = NULL; } - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, NULL, s, wl, wp); shellcmd = format_expand(ft, args->argv[0]); format_free(ft); diff --git a/cmd-split-window.c b/cmd-split-window.c index 859e1559..80d9e2b1 100644 --- a/cmd-split-window.c +++ b/cmd-split-window.c @@ -88,7 +88,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) to_free = NULL; if (args_has(args, 'c')) { - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL, NULL); to_free = cwd = format_expand(ft, args_get(args, 'c')); @@ -165,7 +165,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq) if ((template = args_get(args, 'F')) == NULL) template = SPLIT_WINDOW_TEMPLATE; - ft = format_create(0); + ft = format_create(cmdq, 0); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, wl, new_wp); diff --git a/control-notify.c b/control-notify.c index 7036f6b5..a40f8d7c 100644 --- a/control-notify.c +++ b/control-notify.c @@ -88,7 +88,7 @@ control_notify_window_layout_changed(struct window *w) if (w->layout_root == NULL) continue; - ft = format_create(0); + ft = format_create(NULL, 0); wl = winlink_find_by_window(&s->windows, w); if (wl != NULL) { format_defaults(ft, c, NULL, wl, NULL); diff --git a/format.c b/format.c index 61a911ed..3e666330 100644 --- a/format.c +++ b/format.c @@ -465,7 +465,7 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) /* Create a new tree. */ struct format_tree * -format_create(int flags) +format_create(struct cmd_q *cmdq, int flags) { struct format_tree *ft; @@ -484,6 +484,9 @@ format_create(int flags) format_add(ft, "socket_path", "%s", socket_path); format_add_tv(ft, "start_time", &start_time); + if (cmdq != NULL && cmdq->cmd != NULL) + format_add(ft, "command_name", "%s", cmdq->cmd->entry->name); + return (ft); } diff --git a/names.c b/names.c index 268403e7..3c25e215 100644 --- a/names.c +++ b/names.c @@ -118,7 +118,7 @@ format_window_name(struct window *w) struct format_tree *ft; char *fmt, *name; - ft = format_create(0); + ft = format_create(NULL, 0); format_defaults_window(ft, w); format_defaults_pane(ft, w->active); diff --git a/server-client.c b/server-client.c index 92ce024d..8b6be5d9 100644 --- a/server-client.c +++ b/server-client.c @@ -933,7 +933,7 @@ server_client_set_title(struct client *c) template = options_get_string(s->options, "set-titles-string"); - ft = format_create(0); + ft = format_create(NULL, 0); format_defaults(ft, c, NULL, NULL, NULL); title = format_expand_time(ft, template, time(NULL)); diff --git a/status.c b/status.c index 5539fa31..b555a9de 100644 --- a/status.c +++ b/status.c @@ -500,9 +500,9 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t) return (xstrdup("")); if (c->flags & CLIENT_STATUSFORCE) - ft = format_create(FORMAT_STATUS|FORMAT_FORCE); + ft = format_create(NULL, FORMAT_STATUS|FORMAT_FORCE); else - ft = format_create(FORMAT_STATUS); + ft = format_create(NULL, FORMAT_STATUS); format_defaults(ft, c, NULL, wl, NULL); expanded = format_expand_time(ft, fmt, t); @@ -661,7 +661,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input, int keys; time_t t; - ft = format_create(0); + ft = format_create(NULL, 0); format_defaults(ft, c, NULL, NULL, NULL); t = time(NULL); @@ -722,7 +722,7 @@ status_prompt_update(struct client *c, const char *msg, const char *input) struct format_tree *ft; time_t t; - ft = format_create(0); + ft = format_create(NULL, 0); format_defaults(ft, c, NULL, NULL, NULL); t = time(NULL); diff --git a/tmux.1 b/tmux.1 index cbd01d9e..a0dbd486 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3406,6 +3406,7 @@ The following variables are available, where appropriate: .It Li "client_tty" Ta "" Ta "Pseudo terminal of client" .It Li "client_utf8" Ta "" Ta "1 if client supports utf8" .It Li "client_width" Ta "" Ta "Width of client" +.It Li "command_name" Ta "" Ta "Name of command in use, if any" .It Li "cursor_flag" Ta "" Ta "Pane cursor flag" .It Li "cursor_x" Ta "" Ta "Cursor X position in pane" .It Li "cursor_y" Ta "" Ta "Cursor Y position in pane" diff --git a/tmux.h b/tmux.h index 5df72052..082c9068 100644 --- a/tmux.h +++ b/tmux.h @@ -1492,7 +1492,7 @@ char *paste_make_sample(struct paste_buffer *); #define FORMAT_STATUS 0x1 #define FORMAT_FORCE 0x2 struct format_tree; -struct format_tree *format_create(int); +struct format_tree *format_create(struct cmd_q *, int); void format_free(struct format_tree *); void printflike(3, 4) format_add(struct format_tree *, const char *, const char *, ...); diff --git a/window-choose.c b/window-choose.c index 862531fb..35170c65 100644 --- a/window-choose.c +++ b/window-choose.c @@ -186,7 +186,7 @@ window_choose_data_create(int type, struct client *c, struct session *s) wcd = xmalloc(sizeof *wcd); wcd->type = type; - wcd->ft = format_create(0); + wcd->ft = format_create(NULL, 0); wcd->ft_template = NULL; wcd->command = NULL; diff --git a/window-copy.c b/window-copy.c index eb17460d..e09a504c 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1480,7 +1480,7 @@ window_copy_copy_pipe(struct window_pane *wp, struct session *sess, if (buf == NULL) return; - ft = format_create(0); + ft = format_create(NULL, 0); format_defaults(ft, NULL, sess, NULL, wp); expanded = format_expand(ft, arg);