Support #(command) in status-left, and status-right.

pull/1/head
Tiago Cunha 2009-01-29 23:35:14 +00:00
parent 871f57cb63
commit 2bb499c8af
3 changed files with 63 additions and 3 deletions

View File

@ -1,3 +1,9 @@
29 January 2009
* Support #(command) in status-left, and status-right, which is displayed as
the first line of command's output (e.g. set -g status-right
"#(whoami)@#(hostname -s)"). Commands with )s aren't supported.
28 January 2009
* Support mouse in copy mode to move cursor. Can't do anything else at the
@ -1037,7 +1043,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
$Id: CHANGES,v 1.240 2009-01-28 22:00:22 nicm Exp $
$Id: CHANGES,v 1.241 2009-01-29 23:35:14 tcunha Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

View File

@ -1,4 +1,4 @@
/* $Id: status.c,v 1.68 2009-01-27 20:22:33 nicm Exp $ */
/* $Id: status.c,v 1.69 2009-01-29 23:35:14 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -30,6 +30,7 @@
#include "tmux.h"
char *status_replace(struct session *, char *, time_t);
char *status_replace_popen(char **);
size_t status_width(struct winlink *);
char *status_print(struct session *, struct winlink *, struct grid_cell *);
@ -299,6 +300,7 @@ status_replace(struct session *s, char *fmt, time_t t)
struct winlink *wl = s->curw;
static char out[BUFSIZ];
char in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr;
char *savedptr;
size_t len;
long n;
@ -307,6 +309,7 @@ status_replace(struct session *s, char *fmt, time_t t)
iptr = in;
optr = out;
savedptr = NULL;
while (*iptr != '\0') {
if (optr >= out + (sizeof out) - 1)
@ -325,6 +328,14 @@ status_replace(struct session *s, char *fmt, time_t t)
ptr = NULL;
switch (*iptr++) {
case '(':
if (ptr == NULL) {
ptr = status_replace_popen(&iptr);
if (ptr == NULL)
break;
savedptr = ptr;
}
/* FALLTHROUGH */
case 'H':
if (ptr == NULL) {
if (gethostname(tmp, sizeof tmp) != 0)
@ -353,6 +364,10 @@ status_replace(struct session *s, char *fmt, time_t t)
*optr++ = '#';
break;
}
if (savedptr != NULL) {
xfree(savedptr);
savedptr = NULL;
}
break;
default:
*optr++ = ch;
@ -364,6 +379,44 @@ status_replace(struct session *s, char *fmt, time_t t)
return (xstrdup(out));
}
char *
status_replace_popen(char **iptr)
{
FILE *f;
char *buf = NULL;
char cmd[BUFSIZ];
char *ptr = NULL;
size_t len;
if (**iptr == '\0' || strchr(*iptr, ')') == NULL)
return (NULL);
strlcpy(cmd, *iptr, sizeof cmd);
cmd[strcspn(cmd, ")")] = '\0';
if ((f = popen(cmd, "r")) == NULL)
goto out;
if ((buf = fgetln(f, &len)) == NULL) {
pclose(f);
goto out;
}
if (buf[len - 1] == '\n') {
buf[len - 1] = '\0';
buf = xstrdup(buf);
} else {
ptr = xrealloc(ptr, 1, len + 1);
memcpy(ptr, buf, len);
ptr[len] = '\0';
buf = ptr;
}
pclose(f);
out:
*iptr = (strchr(*iptr, ')') + 1);
return (buf);
}
size_t
status_width(struct winlink *wl)
{

3
tmux.1
View File

@ -1,4 +1,4 @@
.\" $Id: tmux.1,v 1.71 2009-01-27 20:22:33 nicm Exp $
.\" $Id: tmux.1,v 1.72 2009-01-29 23:35:14 tcunha Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@ -857,6 +857,7 @@ By default, nothing is displayed.
may contain any of the following special character pairs:
.Bl -column "Character pair" "Replaced with" -offset indent
.It Sy "Character pair" Ta Sy "Replaced with"
.It Li "#(command)" Ta "First line of command's output"
.It Li "#H" Ta "Hostname of local host"
.It Li "#S" Ta "Session name"
.It Li "#T" Ta "Current window title"