From 5aa3098bb6c25e954cacc168a599d78447b4d005 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 15 Jan 2009 23:42:21 +0000 Subject: [PATCH] Support #S #H in status-left/right. --- CHANGES | 3 ++- TODO | 1 - status.c | 20 +++++++++++++++++--- tmux.1 | 4 +++- tmux.c | 4 ++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 9c8953f2..2d4717c3 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 15 January 2009 +* Support #H for hostname and #S for session name in status-left/right. * Two new commands, choose-window and choose-session which work only when bound to a key and allow the window or session to be selected from a list. These are now bound to "w" and "s" instead of the list commands. @@ -929,7 +930,7 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.212 2009-01-15 19:30:21 nicm Exp $ +$Id: CHANGES,v 1.213 2009-01-15 23:42:21 nicm 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 diff --git a/TODO b/TODO index 6b397dbe..dec6af5a 100644 --- a/TODO +++ b/TODO @@ -62,7 +62,6 @@ soon: - swap-panes - move-pane (to window) - should be able to move to a hidden pane and it would be moved into view -- more # commands in status-left,right eg #H for hostname, #S for session name - command to run something without a window at all - output to window-more - command to purge window history - command: load-buffer -b number filename diff --git a/status.c b/status.c index 59ccdc62..bdb7e303 100644 --- a/status.c +++ b/status.c @@ -1,4 +1,4 @@ -/* $Id: status.c,v 1.62 2009-01-14 19:29:32 nicm Exp $ */ +/* $Id: status.c,v 1.63 2009-01-15 23:42:21 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -25,6 +25,7 @@ #include #include #include +#include #include "tmux.h" @@ -291,7 +292,7 @@ status_replace(struct session *s, char *fmt, time_t t) { struct winlink *wl = s->curw; static char out[BUFSIZ]; - char in[BUFSIZ], ch, *iptr, *optr, *ptr, *endptr; + char in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr; size_t len; long n; @@ -316,9 +317,22 @@ status_replace(struct session *s, char *fmt, time_t t) if (n <= 0) n = LONG_MAX; + ptr = NULL; switch (*iptr++) { + case 'H': + if (ptr == NULL) { + if (gethostname(tmp, sizeof tmp) != 0) + fatal("gethostname"); + ptr = tmp; + } + /* FALLTHROUGH */ + case 'S': + if (ptr == NULL) + ptr = s->name; + /* FALLTHROUGH */ case 'T': - ptr = wl->window->active->base.title; + if (ptr == NULL) + ptr = wl->window->active->base.title; len = strlen(ptr); if ((size_t) n < len) len = n; diff --git a/tmux.1 b/tmux.1 index 43495881..3677c9b5 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1,4 +1,4 @@ -.\" $Id: tmux.1,v 1.61 2009-01-15 21:24:03 tcunha Exp $ +.\" $Id: tmux.1,v 1.62 2009-01-15 23:42:21 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -759,6 +759,8 @@ 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 "#H" Ta "Hostname of local host" +.It Li "#S" Ta "Session name" .It Li "#T" Ta "Current window title" .It Li "##" Ta "A literal" Ql # .El diff --git a/tmux.c b/tmux.c index 81738f24..9f33d7e8 100644 --- a/tmux.c +++ b/tmux.c @@ -1,4 +1,4 @@ -/* $Id: tmux.c,v 1.96 2009-01-14 22:13:30 nicm Exp $ */ +/* $Id: tmux.c,v 1.97 2009-01-15 23:42:21 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -243,7 +243,7 @@ main(int argc, char **argv) options_set_number(&global_options, "status-interval", 15); options_set_number(&global_options, "status-left-length", 10); options_set_number(&global_options, "status-right-length", 40); - options_set_string(&global_options, "status-left", "%s", ""); /* ugh */ + options_set_string(&global_options, "status-left", "[#S]"); options_set_string( &global_options, "status-right", "\"#24T\" %%H:%%M %%d-%%b-%%y"); options_init(&global_window_options, NULL);