=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/names.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- src/usr.bin/tmux/names.c 2013/03/25 15:59:57 1.21 +++ src/usr.bin/tmux/names.c 2013/10/10 11:56:50 1.22 @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.21 2013/03/25 15:59:57 nicm Exp $ */ +/* $OpenBSD: names.c,v 1.22 2013/10/10 11:56:50 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -22,12 +22,10 @@ #include #include #include -#include #include "tmux.h" void window_name_callback(unused int, unused short, void *); -char *parse_window_name(const char *); void queue_window_name(struct window *w) @@ -47,7 +45,7 @@ window_name_callback(unused int fd, unused short events, void *data) { struct window *w = data; - char *name, *wname; + char *name; if (w->active == NULL) return; @@ -59,50 +57,40 @@ } queue_window_name(w); - if (w->active->screen != &w->active->base) - name = NULL; - else - name = get_proc_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); - } - - if (w->active->fd == -1) { - xasprintf(&name, "%s[dead]", wname); - free(wname); - wname = name; - } - - if (strcmp(wname, w->name)) { - window_set_name(w, wname); + name = format_window_name(w); + if (strcmp(name, w->name) != 0) { + window_set_name(w, name); server_status_window(w); } - free(wname); + free(name); } char * default_window_name(struct window *w) { - if (w->active->screen != &w->active->base) - return (xstrdup("[tmux]")); if (w->active->cmd != NULL && *w->active->cmd != '\0') return (parse_window_name(w->active->cmd)); return (parse_window_name(w->active->shell)); } char * +format_window_name(struct window *w) +{ + struct format_tree *ft; + char *fmt, *name; + + ft = format_create(); + format_window(ft, w); + format_window_pane(ft, w->active); + + fmt = options_get_string(&w->options, "automatic-rename-format"); + name = format_expand(ft, fmt); + + format_free(ft); + return (name); +} + +char * parse_window_name(const char *in) { char *copy, *name, *ptr; @@ -111,7 +99,7 @@ if (strncmp(name, "exec ", (sizeof "exec ") - 1) == 0) name = name + (sizeof "exec ") - 1; - while (*name == ' ') + while (*name == ' ' || *name == '-') name++; if ((ptr = strchr(name, ' ')) != NULL) *ptr = '\0';