mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Add automatic-rename-format option allowing automatic rename to use
something other than pane_current_command.
This commit is contained in:
parent
2bf2f5d58e
commit
fd1750af49
58
names.c
58
names.c
@ -22,12 +22,10 @@
|
|||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
void window_name_callback(unused int, unused short, void *);
|
void window_name_callback(unused int, unused short, void *);
|
||||||
char *parse_window_name(const char *);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
queue_window_name(struct window *w)
|
queue_window_name(struct window *w)
|
||||||
@ -47,7 +45,7 @@ void
|
|||||||
window_name_callback(unused int fd, unused short events, void *data)
|
window_name_callback(unused int fd, unused short events, void *data)
|
||||||
{
|
{
|
||||||
struct window *w = data;
|
struct window *w = data;
|
||||||
char *name, *wname;
|
char *name;
|
||||||
|
|
||||||
if (w->active == NULL)
|
if (w->active == NULL)
|
||||||
return;
|
return;
|
||||||
@ -59,49 +57,39 @@ window_name_callback(unused int fd, unused short events, void *data)
|
|||||||
}
|
}
|
||||||
queue_window_name(w);
|
queue_window_name(w);
|
||||||
|
|
||||||
if (w->active->screen != &w->active->base)
|
name = format_window_name(w);
|
||||||
name = NULL;
|
if (strcmp(name, w->name) != 0) {
|
||||||
else
|
window_set_name(w, name);
|
||||||
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);
|
|
||||||
server_status_window(w);
|
server_status_window(w);
|
||||||
}
|
}
|
||||||
free(wname);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
default_window_name(struct window *w)
|
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')
|
if (w->active->cmd != NULL && *w->active->cmd != '\0')
|
||||||
return (parse_window_name(w->active->cmd));
|
return (parse_window_name(w->active->cmd));
|
||||||
return (parse_window_name(w->active->shell));
|
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 *
|
char *
|
||||||
parse_window_name(const char *in)
|
parse_window_name(const char *in)
|
||||||
{
|
{
|
||||||
@ -111,7 +99,7 @@ parse_window_name(const char *in)
|
|||||||
if (strncmp(name, "exec ", (sizeof "exec ") - 1) == 0)
|
if (strncmp(name, "exec ", (sizeof "exec ") - 1) == 0)
|
||||||
name = name + (sizeof "exec ") - 1;
|
name = name + (sizeof "exec ") - 1;
|
||||||
|
|
||||||
while (*name == ' ')
|
while (*name == ' ' || *name == '-')
|
||||||
name++;
|
name++;
|
||||||
if ((ptr = strchr(name, ' ')) != NULL)
|
if ((ptr = strchr(name, ' ')) != NULL)
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
@ -482,6 +482,11 @@ const struct options_table_entry window_options_table[] = {
|
|||||||
.default_num = 1
|
.default_num = 1
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ .name = "automatic-rename-format",
|
||||||
|
.type = OPTIONS_TABLE_STRING,
|
||||||
|
.default_str = "#{?pane_in_mode,[tmux],#{pane_current_command}}#{?pane_dead,[dead],}"
|
||||||
|
},
|
||||||
|
|
||||||
{ .name = "c0-change-trigger",
|
{ .name = "c0-change-trigger",
|
||||||
.type = OPTIONS_TABLE_NUMBER,
|
.type = OPTIONS_TABLE_NUMBER,
|
||||||
.default_num = 250,
|
.default_num = 250,
|
||||||
|
Loading…
Reference in New Issue
Block a user