mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	First period not last for host_short, from Michael Scholz.
This commit is contained in:
		
							
								
								
									
										49
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								format.c
									
									
									
									
									
								
							@@ -36,6 +36,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
int	 format_replace(struct format_tree *, const char *, size_t, char **,
 | 
					int	 format_replace(struct format_tree *, const char *, size_t, char **,
 | 
				
			||||||
	     size_t *, size_t *);
 | 
						     size_t *, size_t *);
 | 
				
			||||||
 | 
					char	*format_get_command(struct window_pane *);
 | 
				
			||||||
void	 format_window_pane_tabs(struct format_tree *, struct window_pane *);
 | 
					void	 format_window_pane_tabs(struct format_tree *, struct window_pane *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Format key-value replacement entry. */
 | 
					/* Format key-value replacement entry. */
 | 
				
			||||||
@@ -120,7 +121,7 @@ format_create(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if (gethostname(host, sizeof host) == 0) {
 | 
						if (gethostname(host, sizeof host) == 0) {
 | 
				
			||||||
		format_add(ft, "host", "%s", host);
 | 
							format_add(ft, "host", "%s", host);
 | 
				
			||||||
		if ((ptr = strrchr(host, '.')) != NULL)
 | 
							if ((ptr = strchr(host, '.')) != NULL)
 | 
				
			||||||
			*ptr = '\0';
 | 
								*ptr = '\0';
 | 
				
			||||||
		format_add(ft, "host_short", "%s", host);
 | 
							format_add(ft, "host_short", "%s", host);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -348,6 +349,21 @@ format_expand(struct format_tree *ft, const char *fmt)
 | 
				
			|||||||
	return (buf);
 | 
						return (buf);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Get command name for format. */
 | 
				
			||||||
 | 
					char *
 | 
				
			||||||
 | 
					format_get_command(struct window_pane *wp)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char	*cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cmd = get_proc_name(wp->fd, wp->tty);
 | 
				
			||||||
 | 
						if (cmd == NULL || *cmd == '\0') {
 | 
				
			||||||
 | 
							cmd = wp->cmd;
 | 
				
			||||||
 | 
							if (cmd == NULL || *cmd == '\0')
 | 
				
			||||||
 | 
								cmd = wp->shell;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return (parse_window_name(cmd));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Set default format keys for a session. */
 | 
					/* Set default format keys for a session. */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
format_session(struct format_tree *ft, struct session *s)
 | 
					format_session(struct format_tree *ft, struct session *s)
 | 
				
			||||||
@@ -427,25 +443,38 @@ format_client(struct format_tree *ft, struct client *c)
 | 
				
			|||||||
		format_add(ft, "client_last_session", "%s", s->name);
 | 
							format_add(ft, "client_last_session", "%s", s->name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Set default format keys for a window. */
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					format_window(struct format_tree *ft, struct window *w)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						char	*layout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						layout = layout_dump(w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						format_add(ft, "window_id", "@%u", w->id);
 | 
				
			||||||
 | 
						format_add(ft, "window_name", "%s", w->name);
 | 
				
			||||||
 | 
						format_add(ft, "window_width", "%u", w->sx);
 | 
				
			||||||
 | 
						format_add(ft, "window_height", "%u", w->sy);
 | 
				
			||||||
 | 
						format_add(ft, "window_layout", "%s", layout);
 | 
				
			||||||
 | 
						format_add(ft, "window_panes", "%u", window_count_panes(w));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						free(layout);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Set default format keys for a winlink. */
 | 
					/* Set default format keys for a winlink. */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
 | 
					format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct window	*w = wl->window;
 | 
						struct window	*w = wl->window;
 | 
				
			||||||
	char		*layout, *flags;
 | 
						char		*flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	layout = layout_dump(w);
 | 
					 | 
				
			||||||
	flags = window_printable_flags(s, wl);
 | 
						flags = window_printable_flags(s, wl);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	format_add(ft, "window_id", "@%u", w->id);
 | 
						format_window(ft, w);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	format_add(ft, "window_index", "%d", wl->idx);
 | 
						format_add(ft, "window_index", "%d", wl->idx);
 | 
				
			||||||
	format_add(ft, "window_name", "%s", w->name);
 | 
					 | 
				
			||||||
	format_add(ft, "window_width", "%u", w->sx);
 | 
					 | 
				
			||||||
	format_add(ft, "window_height", "%u", w->sy);
 | 
					 | 
				
			||||||
	format_add(ft, "window_flags", "%s", flags);
 | 
						format_add(ft, "window_flags", "%s", flags);
 | 
				
			||||||
	format_add(ft, "window_layout", "%s", layout);
 | 
					 | 
				
			||||||
	format_add(ft, "window_active", "%d", wl == s->curw);
 | 
						format_add(ft, "window_active", "%d", wl == s->curw);
 | 
				
			||||||
	format_add(ft, "window_panes", "%u", window_count_panes(w));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	format_add(ft, "window_bell_flag", "%u",
 | 
						format_add(ft, "window_bell_flag", "%u",
 | 
				
			||||||
	    !!(wl->flags & WINLINK_BELL));
 | 
						    !!(wl->flags & WINLINK_BELL));
 | 
				
			||||||
@@ -456,8 +485,8 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
 | 
				
			|||||||
	format_add(ft, "window_silence_flag", "%u",
 | 
						format_add(ft, "window_silence_flag", "%u",
 | 
				
			||||||
	    !!(wl->flags & WINLINK_SILENCE));
 | 
						    !!(wl->flags & WINLINK_SILENCE));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	free(flags);
 | 
						free(flags);
 | 
				
			||||||
	free(layout);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Add window pane tabs. */
 | 
					/* Add window pane tabs. */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user