tmux titles-string 没有执行 shell 命令

tmux titles-string not executing shell command

我的 ~/.tmux.conf

中有以下几行
set-option -g set-titles on
set-option -g set-titles-string "#(whoami)@#H: $PWD \"#S\" (#W)#F [#I:#P]"

这在过去有效,但在升级到 2.0 后 shell 命令不再执行。我现在在我的标题中看到:

#(whoami)@myhostname.local: /Users/lander [..rest..]

根据手册页,这应该有效:

status-left string
                 Display string (by default the session name) to the left of the status
                 bar.  string will be passed through strftime(3) and formats (see
                 FORMATS) will be expanded.  It may also contain any of the following
                 special character sequences:

                       Character pair    Replaced with
                       #(shell-command)  First line of the command's output
                       #[attributes]     Colour or attribute change
                       ##                A literal `#'

执行您提到的任务的代码在 2.0 版中不再存在。这是对上述问题的简短回答。文档尚未更新以反映这一点,或者这是意外完成的并且是一个错误。

以下正是我认为是这种情况的原因。我的午休时间快结束了,所以我现在无法为此创建补丁。如果没有其他人可以从这里解决这个问题,我会在这个周末试一试。

我检查了 git repository 并查看了版本 1.9a -> 2.0 的代码更改。

实际执行此替换的函数是 status.c 中的 status_replace()。这似乎仍然有效,因为命令处理在状态行中进行,它仍然调用此函数。

在版本 1.9a 中,这也是从 server-client.c 中的 server_client_set_title() 调用的,大约在第 770 行。它看起来像这样:

void
server_client_set_title(struct client *c)
{
    struct session  *s = c->session;
    const char  *template;
    char        *title;

    template = options_get_string(&s->options, "set-titles-string");

    title = status_replace(c, NULL, NULL, NULL, template, time(NULL), 1);
    if (c->title == NULL || strcmp(title, c->title) != 0) {
        free(c->title);
        c->title = xstrdup(title);
        tty_set_title(&c->tty, c->title);
    }
    free(title);
}

在 2.0 版中,此调用已替换为(现在在第 947 行左右):

void
server_client_set_title(struct client *c)
{
    struct session      *s = c->session;
    const char      *template;
    char            *title;
    struct format_tree  *ft;

    template = options_get_string(&s->options, "set-titles-string");

    ft = format_create();
    format_defaults(ft, c, NULL, NULL, NULL);

    title = format_expand_time(ft, template, time(NULL));
    if (c->title == NULL || strcmp(title, c->title) != 0) {
        free(c->title);
        c->title = xstrdup(title);
        tty_set_title(&c->tty, c->title);
    }
    free(title);

    format_free(ft);
}

看起来对 format_expand_time() 和 status_replace() 的调用可能是互斥的。这是可能需要花费一些精力来修复的部分——在不破坏他们刚刚添加的任何新功能的情况下将旧函数调用放回那里。

阅读代码做得很好,它真的很简单:set-titles-string 切换为使用不扩展 #() 的格式。修补这个很容易,不,将 status_print() 恢复到 tmux.h 还不够好,相反,工作扩展应该是一个单独的函数,并从 status_replace() 和 format_expand()。不知道什么时候完成。

感谢参与