Lander
Lander

Reputation: 3437

tmux titles-string not executing shell command

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

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

This has worked in the past but after upgrading to 2.0 shell commands are no longer executed. I now 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's output
                       #[attributes]     Colour or attribute change
                       ##                A literal `#'

Upvotes: 4

Views: 943

Answers (2)

ThomasAdam
ThomasAdam

Reputation: 194

Well done for reading the code, it's simple really: set-titles-string switched to using formats which don't expand #(). Patching this is easy, and no, it's not good enough to reinstate status_print() to tmux.h, instead, job expansion should be a separate function and used from status_replace() and format_expand(). No idea when this will get done.

Thanks for playing.

Upvotes: 2

Barry Gackle
Barry Gackle

Reputation: 839

The code that performed the task your are mentioning is no longer present in version 2.0. That's the short answer to the question above. Either the documentation hasn't been updated to reflect this, or this was done accidentally and is a bug.

What follows is exactly why I think this is the case. I'm at the end of my lunch break, so I can't create a patch for this right now. If no one else gets around to fixing this from here, I will take a stab at it this weekend.

I checkout out the git repository and took a look at code changes from version 1.9a -> 2.0.

The function that actually does this replacement is status_replace() in status.c. This still seems to work, as the command processing works in the status lines, which still call this function.

In version 1.9a, this was also called from server_client_set_title() in server-client.c, around 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 with (now down around 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 calls to format_expand_time() and status_replace() might be mutually exclusive. That is the part that might take a bit of effort to fix -- getting the old function call back in there without breaking whatever new functionality they've just added.

Upvotes: 1

Related Questions