From d388dbdea9ceacacadc27a36ccc968fa7d6070ec Mon Sep 17 00:00:00 2001 From: nicm <nicm> Date: Wed, 8 Apr 2020 10:58:09 +0000 Subject: [PATCH 1/3] Pass the cmd item to format expansion so that mouse formats work. --- cmd-display-menu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd-display-menu.c b/cmd-display-menu.c index 852c540e..b4db7331 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -190,7 +190,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_NORMAL); if (args_has(args, 'T')) - title = format_single(NULL, args_get(args, 'T'), c, s, wl, wp); + title = format_single(item, args_get(args, 'T'), c, s, wl, wp); else title = xstrdup(""); @@ -298,13 +298,13 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item) value = args_get(args, 'd'); if (value != NULL) - cwd = format_single(NULL, value, c, fs->s, fs->wl, fs->wp); + cwd = format_single(item, value, c, fs->s, fs->wl, fs->wp); else cwd = xstrdup(server_client_get_cwd(c, fs->s)); value = args_get(args, 'R'); if (value != NULL) - shellcmd = format_single(NULL, value, c, fs->s, fs->wl, fs->wp); + shellcmd = format_single(item, value, c, fs->s, fs->wl, fs->wp); if (args_has(args, 'K')) flags |= POPUP_WRITEKEYS; From 5d0eb619f18b1ed98d0ecf492dddf66ab49bed03 Mon Sep 17 00:00:00 2001 From: nicm <nicm> Date: Wed, 8 Apr 2020 11:26:07 +0000 Subject: [PATCH 2/3] Restore pane_current_path format from portable tmux, it is no longer used by default and is very useful. --- format.c | 16 ++++++++++++++++ procname.c | 15 +++++++++++++++ tmux.1 | 1 + tmux.h | 1 + 4 files changed, 33 insertions(+) diff --git a/format.c b/format.c index 815be8da..6300b332 100644 --- a/format.c +++ b/format.c @@ -741,6 +741,21 @@ format_cb_current_command(struct format_tree *ft, struct format_entry *fe) free(cmd); } +/* Callback for pane_current_path. */ +static void +format_cb_current_path(struct format_tree *ft, struct format_entry *fe) +{ + struct window_pane *wp = ft->wp; + char *cwd; + + if (wp == NULL) + return; + + cwd = get_proc_cwd(wp->fd); + if (cwd != NULL) + fe->value = xstrdup(cwd); +} + /* Callback for history_bytes. */ static void format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe) @@ -2722,6 +2737,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_pid", "%ld", (long) wp->pid); format_add_cb(ft, "pane_start_command", format_cb_start_command); format_add_cb(ft, "pane_current_command", format_cb_current_command); + format_add_cb(ft, "pane_current_path", format_cb_current_path); format_add(ft, "cursor_x", "%u", wp->base.cx); format_add(ft, "cursor_y", "%u", wp->base.cy); diff --git a/procname.c b/procname.c index 07a8a56c..45e508ef 100644 --- a/procname.c +++ b/procname.c @@ -38,6 +38,7 @@ static struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *); char *get_proc_name(int, char *); +char *get_proc_cwd(int); static struct kinfo_proc * cmp_procs(struct kinfo_proc *p1, struct kinfo_proc *p2) @@ -132,3 +133,17 @@ error: free(buf); return (NULL); } + +char * +get_proc_cwd(int fd) +{ + int name[] = { CTL_KERN, KERN_PROC_CWD, 0 }; + static char path[MAXPATHLEN]; + size_t pathlen = sizeof path; + + if ((name[2] = tcgetpgrp(fd)) == -1) + return (NULL); + if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) + return (NULL); + return (path); +} diff --git a/tmux.1 b/tmux.1 index 00231c08..c62d543b 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4409,6 +4409,7 @@ The following variables are available, where appropriate: .It Li "pane_at_top" Ta "" Ta "1 if pane is at the top of window" .It Li "pane_bottom" Ta "" Ta "Bottom of pane" .It Li "pane_current_command" Ta "" Ta "Current command if available" +.It Li "pane_current_path" Ta "" Ta "Current path if available" .It Li "pane_dead" Ta "" Ta "1 if pane is dead" .It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane" .It Li "pane_format" Ta "" Ta "1 if format is for a pane" diff --git a/tmux.h b/tmux.h index fbf10cf4..fd739974 100644 --- a/tmux.h +++ b/tmux.h @@ -2743,6 +2743,7 @@ int utf8_cstrhas(const char *, const struct utf8_data *); /* procname.c */ char *get_proc_name(int, char *); +char *get_proc_cwd(int); /* log.c */ void log_add_level(void); From ff135b34a41b388b9ac98e2f655cf487ace6aa43 Mon Sep 17 00:00:00 2001 From: nicm <nicm> Date: Thu, 9 Apr 2020 06:28:55 +0000 Subject: [PATCH 3/3] Mention paste at same place as copy, suggested by John Boyle. --- tmux.1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tmux.1 b/tmux.1 index c62d543b..d17c19e9 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1425,6 +1425,10 @@ This mode is entered with the command, bound to .Ql \&[ by default. +Copied text can be pasted with the +.Ic paste-buffer +command, bound to +.Ql \&] . .It View mode, which is like copy mode but is entered when a command that produces output, such as