summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2017-05-05 11:59:48 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2017-05-05 11:59:48 +0000
commitbaa0798c6b6a1b1bb59cad4eca74cb65c2485251 (patch)
treef82b3b7fed2707b1fa63b6e3b57c347f6e66f516 /usr.bin
parent294b6baaa271db823ed761f469c31c90fab84d66 (diff)
Add some formats to look at the session window stack, suggested by Scott
ROCHFORD.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/format.c69
-rw-r--r--usr.bin/tmux/tmux.16
2 files changed, 52 insertions, 23 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 69f35bd31d2..c1e7e496c7c 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.132 2017/05/03 05:53:34 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.133 2017/05/05 11:59:47 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -42,25 +42,6 @@ typedef void (*format_cb)(struct format_tree *, struct format_entry *);
static char *format_job_get(struct format_tree *, const char *);
static void format_job_timer(int, short, void *);
-static void format_cb_host(struct format_tree *, struct format_entry *);
-static void format_cb_host_short(struct format_tree *,
- struct format_entry *);
-static void format_cb_pid(struct format_tree *, struct format_entry *);
-static void format_cb_session_alerts(struct format_tree *,
- struct format_entry *);
-static void format_cb_window_layout(struct format_tree *,
- struct format_entry *);
-static void format_cb_window_visible_layout(struct format_tree *,
- struct format_entry *);
-static void format_cb_start_command(struct format_tree *,
- struct format_entry *);
-static void format_cb_current_command(struct format_tree *,
- struct format_entry *);
-static void format_cb_history_bytes(struct format_tree *,
- struct format_entry *);
-static void format_cb_pane_tabs(struct format_tree *,
- struct format_entry *);
-
static char *format_find(struct format_tree *, const char *, int);
static void format_add_cb(struct format_tree *, const char *, format_cb);
static void format_add_tv(struct format_tree *, const char *,
@@ -126,6 +107,7 @@ struct format_entry {
/* Format entry tree. */
struct format_tree {
struct window *w;
+ struct winlink *wl;
struct session *s;
struct window_pane *wp;
@@ -416,7 +398,7 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe)
{
struct session *s = ft->s;
struct winlink *wl;
- char alerts[256], tmp[16];
+ char alerts[1024], tmp[16];
if (s == NULL)
return;
@@ -440,6 +422,48 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe)
fe->value = xstrdup(alerts);
}
+/* Callback for session_stack. */
+static void
+format_cb_session_stack(struct format_tree *ft, struct format_entry *fe)
+{
+ struct session *s = ft->s;
+ struct winlink *wl;
+ char result[1024], tmp[16];
+
+ if (s == NULL)
+ return;
+
+ xsnprintf(result, sizeof result, "%u", s->curw->idx);
+ TAILQ_FOREACH(wl, &s->lastw, sentry) {
+ xsnprintf(tmp, sizeof tmp, "%u", wl->idx);
+
+ if (*result != '\0')
+ strlcat(result, ",", sizeof result);
+ strlcat(result, tmp, sizeof result);
+ }
+ fe->value = xstrdup(result);
+}
+
+/* Callback for window_stack_index. */
+static void
+format_cb_window_stack_index(struct format_tree *ft, struct format_entry *fe)
+{
+ struct session *s = ft->wl->session;
+ struct winlink *wl;
+ u_int idx;
+
+ idx = 0;
+ TAILQ_FOREACH(wl, &s->lastw, sentry) {
+ idx++;
+ if (wl == ft->wl)
+ break;
+ }
+ if (wl != NULL)
+ xasprintf(&fe->value, "%u", idx);
+ else
+ fe->value = xstrdup("0");
+}
+
/* Callback for window_layout. */
static void
format_cb_window_layout(struct format_tree *ft, struct format_entry *fe)
@@ -1200,6 +1224,7 @@ format_defaults_session(struct format_tree *ft, struct session *s)
format_add(ft, "session_many_attached", "%d", s->attached > 1);
format_add_cb(ft, "session_alerts", format_cb_session_alerts);
+ format_add_cb(ft, "session_stack", format_cb_session_stack);
}
/* Set default format keys for a client. */
@@ -1286,10 +1311,12 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl)
if (ft->w == NULL)
ft->w = wl->window;
+ ft->wl = wl;
format_defaults_window(ft, w);
format_add(ft, "window_index", "%d", wl->idx);
+ format_add_cb(ft, "window_stack_index", format_cb_window_stack_index);
format_add(ft, "window_flags", "%s", window_printable_flags(wl));
format_add(ft, "window_active", "%d", wl == s->curw);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index ca2a9b4704c..08c16786604 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.547 2017/05/04 07:16:43 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.548 2017/05/05 11:59:47 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 4 2017 $
+.Dd $Mdocdate: May 5 2017 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -3586,6 +3586,7 @@ The following variables are available, where appropriate:
.It Li "session_id" Ta "" Ta "Unique session ID"
.It Li "session_many_attached" Ta "" Ta "1 if multiple clients attached"
.It Li "session_name" Ta "#S" Ta "Name of session"
+.It Li "session_stack" Ta "" Ta "Window indexes in most recent order"
.It Li "session_width" Ta "" Ta "Width of session"
.It Li "session_windows" Ta "" Ta "Number of windows in session"
.It Li "socket_path" Ta "" Ta "Server socket path"
@@ -3605,6 +3606,7 @@ The following variables are available, where appropriate:
.It Li "window_name" Ta "#W" Ta "Name of window"
.It Li "window_panes" Ta "" Ta "Number of panes in window"
.It Li "window_silence_flag" Ta "" Ta "1 if window has silence alert"
+.It Li "window_stack_index" Ta "" Ta "Index in session most recent stack"
.It Li "window_visible_layout" Ta "" Ta "Window layout description, respecting zoomed window panes"
.It Li "window_width" Ta "" Ta "Width of window"
.It Li "window_zoomed_flag" Ta "" Ta "1 if window is zoomed"