On Mon, Dec 10, 2012 at 06:11:09PM +0000, Nicholas Marriott wrote: > Yes I would be happier with a format for automatic rename, it should not > be hard to do.
Here's something for someone to pick up, if they want to: diff --git a/format.c b/format.c index 19f322a..9a9ce8d 100644 --- a/format.c +++ b/format.c @@ -392,6 +392,8 @@ 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", osdep_get_name(wp->window->active->fd, + wp->window->active->tty)); format_add(ft, "pane_pid", "%ld", (long) wp->pid); format_add(ft, "pane_tty", "%s", wp->tty); } diff --git a/names.c b/names.c index 72f1ad1..ba5c4bb 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,10 +64,26 @@ 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 (name_template == NULL) + name_template = AUTOMATIC_RENAME_TEMPLATE; + if (w->active->screen != &w->active->base) name = NULL; else - name = osdep_get_name(w->active->fd, w->active->tty); + name = format_expand(ft, name_template); if (name == NULL) wname = default_window_name(w); else { @@ -91,6 +111,7 @@ window_name_callback(unused int fd, unused short events, void *data) server_status_window(w); } free(wname); + format_free(ft); } char * diff --git a/options-table.c b/options-table.c index 4d1edbd..62a9025 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 = AUTOMATIC_RENAME_TEMPLATE + }, { .name = "c0-change-trigger", .type = OPTIONS_TABLE_NUMBER, diff --git a/tmux.h b/tmux.h index 960d130..c0bc331 100644 --- a/tmux.h +++ b/tmux.h @@ -158,6 +158,9 @@ extern char **environ; #define NEW_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE #define SPLIT_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE +/* Default template for automatic-rename */ +#define AUTOMATIC_RENAME_TEMPLATE "#{window_name}" + /* Bell option values. */ #define BELL_NONE 0 #define BELL_ANY 1 -- 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