Tmux titles-string does not execute shell command

I have the following lines in ~/.tmux.conf

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

      

This worked in the past, but after upgrading to 2.0, shell commands are no longer executed. Now I see in my title:

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

According to the man page, this should work:

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 output
                       #[attributes]     Colour or attribute change
                       ##                A literal `#'

      

+3


source to share


2 answers


Good for reading code, it's simple: set-titles-string switches to use formats that are not expanded by # (). The fix is ​​easy, and no, not enough to restore status_print () in tmux.h, instead the work extension should be a separate function and used from status_replace () and format_expand (). I don't know when this will be done.



Thanks for the game.

+2


source


The code that performed the task you mention is no longer present in version 2.0. ... This is a short answer to the question above. Either the documentation has not been updated to reflect this, or it was by accident and is a bug.

What follows is why I think so. I'm at the end of my lunch break so I can't create a patch for this right now. If no one else finds out to fix it here, I'll hit him this weekend.

I am checking out the git repository and have looked at the code changes from 1.9a -> 2.0.

The function that actually performs this replacement is status_replace () in status.c. This still works because command processing works on status bars that still call this function.

In version 1.9a, this was also called from server_client_set_title () in server-client.c, on line 770. It looks like this:



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);
}

      

In version 2.0 this call has been replaced (now on line 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);
}

      

It looks like the calls to format_expand_time () and status_replace () might be mutually exclusive. This is the part that might go into a bit of effort to fix it - get the old function call back in there without breaking any new functionality they just added.

+1


source







All Articles