I didn't resend the entire patch, only the modified parts. Here are all the changes:
diff --git a/format.c b/format.c index 19f322a..9d151fe 100644 --- a/format.c +++ b/format.c @@ -150,7 +150,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, char **buf, size_t *len, size_t *off) { char *copy, *ptr; - const char *value; + const char *value, *rvalue; size_t valuelen; /* Make a copy of the key. */ @@ -181,6 +181,12 @@ format_replace(struct format_tree *ft, goto fail; value = ptr + 1; } + + if (*value == '#') { + rvalue = format_find(ft, value + 1); + if (rvalue != NULL) + value = rvalue; + } } else { value = format_find(ft, copy); if (value == NULL) @@ -365,6 +371,9 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) unsigned long long size; u_int i; u_int idx; + char *command_name; + + command_name = pane_command_name(wp->window->active); size = 0; for (i = 0; i < gd->hsize; i++) { @@ -392,8 +401,13 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp) if (wp->cwd != NULL) format_add(ft, "pane_start_path", "%s", wp->cwd); format_add(ft, "pane_current_path", "%s", osdep_get_cwd(wp->fd)); + format_add(ft, "pane_current_program", "%s", command_name); + format_add(ft, "pane_default_command", "%d", + !strcmp(basename(wp->shell), command_name)); format_add(ft, "pane_pid", "%ld", (long) wp->pid); format_add(ft, "pane_tty", "%s", wp->tty); + + free(command_name); } void diff --git a/names.c b/names.c index 72f1ad1..2426610 100644 --- a/names.c +++ b/names.c @@ -47,8 +47,12 @@ queue_window_name(struct window *w) void window_name_callback(unused int fd, unused short events, void *data) { - struct window *w = data; - char *name, *wname; + struct window *w = data; + struct winlink *wl; + struct format_tree *ft; + struct session *s, *s2; + char *name, *wname; + const char *name_template; if (w->active == NULL) return; @@ -60,25 +64,25 @@ window_name_callback(unused int fd, unused short events, void *data) } queue_window_name(w); + ft = format_create(); + RB_FOREACH(s2, sessions, &sessions) { + if ((wl = winlink_find_by_window(&s2->windows, w)) == NULL) + continue; + s = s2; + } + + if (wl != NULL && s != NULL) + format_winlink(ft, s, wl); + + format_window_pane(ft, w->active); + + name_template = options_get_string(&w->options, + "automatic-rename-format"); + if (w->active->screen != &w->active->base) - name = NULL; - else - name = osdep_get_name(w->active->fd, w->active->tty); - if (name == NULL) wname = default_window_name(w); - else { - /* - * If tmux is using the default command, it will be a login - * shell and argv[0] may have a - prefix. Remove this if it is - * present. Ick. - */ - if (w->active->cmd != NULL && *w->active->cmd == '\0' && - name != NULL && name[0] == '-' && name[1] != '\0') - wname = parse_window_name(name + 1); - else - wname = parse_window_name(name); - free(name); - } + else + wname = format_expand(ft, name_template); if (w->active->fd == -1) { xasprintf(&name, "%s[dead]", wname); @@ -91,6 +95,7 @@ window_name_callback(unused int fd, unused short events, void *data) server_status_window(w); } free(wname); + format_free(ft); } char * @@ -129,3 +134,24 @@ parse_window_name(const char *in) free(copy); return (name); } + +char * +pane_command_name(struct window_pane *pane) { + char *name, *pname; + + name = osdep_get_name(pane->fd, pane->tty); + + /* + * If tmux is using the default command, it will be a login + * shell and argv[0] may have a - prefix. Remove this if it is + * present. Ick. + */ + if (pane->cmd != NULL && *pane->cmd == '\0' && + name != NULL && name[0] == '-' && name[1] != '\0') + pname = parse_window_name(name + 1); + else + pname = parse_window_name(name); + free(name); + + return (pname); +} diff --git a/options-table.c b/options-table.c index 4d1edbd..fa6d052 100644 --- a/options-table.c +++ b/options-table.c @@ -469,6 +469,10 @@ const struct options_table_entry window_options_table[] = { .default_num = 1 }, + { .name = "automatic-rename-format", + .type = OPTIONS_TABLE_STRING, + .default_str = "#{pane_current_program}" + }, { .name = "c0-change-trigger", .type = OPTIONS_TABLE_NUMBER, diff --git a/tmux.h b/tmux.h index 7de43a8..0f959de 100644 --- a/tmux.h +++ b/tmux.h @@ -2243,6 +2243,7 @@ struct window_choose_data *window_choose_add_item(struct window_pane *, /* names.c */ void queue_window_name(struct window *); char *default_window_name(struct window *); +char *pane_command_name(struct window_pane *); /* signal.c */ void set_signals(void(*)(int, short, void *)); On Tue, Dec 11, 2012 at 8:12 AM, Thomas Adam <tho...@xteddy.org> wrote: > On 11 December 2012 05:13, Patricio Palladino > <em...@patriciopalladino.com> wrote: >> Hi, >> >> The pane_default_command test was incomplete in that patch. Here I >> corrected it, and also implemented the feature I mentioned in the >> previous mail. With this conditional replacement support variables as >> values with #variable_name. And with this, I finally can get tmux >> automatic renaming work as I wanted :D >> >> Here is the patch: > > Where's the code to tie in the window title to use formatting, per > some window option? Or did I miss something here? > > -- Thomas Adam ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users