diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-11-02 18:27:36 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-11-02 18:27:36 +0000 |
commit | 9e6371cb8e9e93df926bbe4acde7582fc1a6b39a (patch) | |
tree | a3584bb78d8353b827282864bf777b46e2cc504e /usr.bin | |
parent | 6cc94558c241acdb0ca077e6c59de00b9cd16f33 (diff) |
Only show the first member of session groups in tree mode (-G flag
disables).
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-choose-tree.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/format.c | 43 | ||||
-rw-r--r-- | usr.bin/tmux/session.c | 8 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 11 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 | ||||
-rw-r--r-- | usr.bin/tmux/window-tree.c | 17 |
6 files changed, 68 insertions, 20 deletions
diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index b33e1e90318..8ba096952ef 100644 --- a/usr.bin/tmux/cmd-choose-tree.c +++ b/usr.bin/tmux/cmd-choose-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-choose-tree.c,v 1.39 2017/08/23 09:39:11 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.40 2017/11/02 18:27:35 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam <thomas@xteddy.org> @@ -30,8 +30,8 @@ const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", .alias = NULL, - .args = { "F:f:NO:st:w", 0, 1 }, - .usage = "[-Nsw] [-F format] [-f filter] [-O sort-order] " + .args = { "F:Gf:NO:st:w", 0, 1 }, + .usage = "[-GNsw] [-F format] [-f filter] [-O sort-order] " CMD_TARGET_PANE_USAGE, .target = { 't', CMD_FIND_PANE, 0 }, diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 9ccb7ed9ffa..9dcca0e2810 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.147 2017/10/12 11:32:27 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.148 2017/11/02 18:27:35 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -572,8 +572,38 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe) evbuffer_add(buffer, ",", 1); evbuffer_add_printf(buffer, "%u", i); } - size = EVBUFFER_LENGTH(buffer); - xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); + if ((size = EVBUFFER_LENGTH(buffer)) != 0) + xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); + evbuffer_free(buffer); +} + +/* Callback for session_group_others. */ +static void +format_cb_session_group_others(struct format_tree *ft, struct format_entry *fe) +{ + struct session *s = ft->s; + struct session_group *sg; + struct session *loop; + struct evbuffer *buffer; + int size; + + if (s == NULL) + return; + sg = session_group_contains(s); + if (sg == NULL) + return; + + buffer = evbuffer_new(); + TAILQ_FOREACH(loop, &sg->sessions, gentry) { + if (loop == s) + continue; + + if (EVBUFFER_LENGTH(buffer) > 0) + evbuffer_add(buffer, ",", 1); + evbuffer_add_printf(buffer, "%s", loop->name); + } + if ((size = EVBUFFER_LENGTH(buffer)) != 0) + xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer)); evbuffer_free(buffer); } @@ -1253,8 +1283,13 @@ format_defaults_session(struct format_tree *ft, struct session *s) sg = session_group_contains(s); format_add(ft, "session_grouped", "%d", sg != NULL); - if (sg != NULL) + if (sg != NULL) { format_add(ft, "session_group", "%s", sg->name); + format_add(ft, "session_group_size", "%u", + session_group_count (sg)); + format_add_cb(ft, "session_group_others", + format_cb_session_group_others); + } format_add_tv(ft, "session_created", &s->creation_time); format_add_tv(ft, "session_last_attached", &s->last_attached_time); diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c index c45b71cac47..bf2e078bf6f 100644 --- a/usr.bin/tmux/session.c +++ b/usr.bin/tmux/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.77 2017/07/09 22:33:09 nicm Exp $ */ +/* $OpenBSD: session.c,v 1.78 2017/11/02 18:27:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -39,10 +39,6 @@ static struct winlink *session_next_alert(struct winlink *); static struct winlink *session_previous_alert(struct winlink *); static void session_group_remove(struct session *); -static u_int session_group_count(struct session_group *); -static void session_group_synchronize1(struct session *, struct session *); - -static u_int session_group_count(struct session_group *); static void session_group_synchronize1(struct session *, struct session *); RB_GENERATE(sessions, session, entry, session_cmp); @@ -624,7 +620,7 @@ session_group_remove(struct session *s) } /* Count number of sessions in session group. */ -static u_int +u_int session_group_count(struct session_group *sg) { struct session *s; diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index cb804c7d1e1..71738c2fd8a 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.585 2017/10/26 08:17:12 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.586 2017/11/02 18:27:35 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: October 26 2017 $ +.Dd $Mdocdate: November 2 2017 $ .Dt TMUX 1 .Os .Sh NAME @@ -1428,7 +1428,7 @@ starts without the preview. This command works only if at least one client is attached. .It Xo .Ic choose-tree -.Op Fl Nsw +.Op Fl GNsw .Op Fl F Ar format .Op Fl f Ar filter .Op Fl O Ar sort-order @@ -1484,6 +1484,9 @@ If a filter would lead to an empty list, it is ignored. specifies the format for each item in the tree. .Fl N starts without the preview. +.Fl G +includes all sessions in any session groups in the tree rather than only the +first. This command works only if at least one client is attached. .It Xo .Ic display-panes @@ -3710,6 +3713,8 @@ The following variables are available, where appropriate: .It Li "session_format" Ta "" Ta "1 if format is for a session (not assuming the current)" .It Li "session_last_attached" Ta "" Ta "Time session last attached" .It Li "session_group" Ta "" Ta "Name of session group" +.It Li "session_group_size" Ta "" Ta "Size of session group" +.It Li "session_group_others" Ta "" Ta "List of other sessions in group" .It Li "session_grouped" Ta "" Ta "1 if session in a group" .It Li "session_height" Ta "" Ta "Height of session" .It Li "session_id" Ta "" Ta "Unique session ID" diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index ec6789147df..55d1dca386e 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.808 2017/10/25 11:26:11 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.809 2017/11/02 18:27:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -2335,6 +2335,7 @@ struct session_group *session_group_new(const char *); void session_group_add(struct session_group *, struct session *); void session_group_synchronize_to(struct session *); void session_group_synchronize_from(struct session *); +u_int session_group_count(struct session_group *); void session_renumber_windows(struct session *); /* utf8.c */ diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index e1c291eefcb..b650ce49caa 100644 --- a/usr.bin/tmux/window-tree.c +++ b/usr.bin/tmux/window-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-tree.c,v 1.22 2017/10/26 08:17:12 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.23 2017/11/02 18:27:35 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -43,8 +43,12 @@ static void window_tree_key(struct window_pane *, "#{?#{==:#{window_panes},1}, \"#{pane_title}\",}" \ "," \ "#{session_windows} windows" \ - "#{?session_grouped, (group ,}" \ - "#{session_group}#{?session_grouped,),}" \ + "#{?session_grouped, " \ + "(group #{session_group}" \ + "#{?session_group_others," \ + " with #{session_group_others}," \ + "})," \ + "}" \ "#{?session_attached, (attached),}" \ "}" \ "}" @@ -91,6 +95,7 @@ struct window_tree_modedata { struct mode_tree_data *data; char *format; char *command; + int squash_groups; struct window_tree_itemdata **item_list; u_int item_size; @@ -394,6 +399,7 @@ window_tree_build(void *modedata, u_int sort_type, uint64_t *tag, { struct window_tree_modedata *data = modedata; struct session *s, **l; + struct session_group *sg; u_int n, i; for (i = 0; i < data->item_size; i++) @@ -405,6 +411,10 @@ window_tree_build(void *modedata, u_int sort_type, uint64_t *tag, l = NULL; n = 0; RB_FOREACH(s, sessions, &sessions) { + if (data->squash_groups && + (sg = session_group_contains(s)) != NULL && + s != TAILQ_FIRST(&sg->sessions)) + continue; l = xreallocarray(l, n + 1, sizeof *l); l[n++] = s; } @@ -805,6 +815,7 @@ window_tree_init(struct window_pane *wp, struct cmd_find_state *fs, data->command = xstrdup(WINDOW_TREE_DEFAULT_COMMAND); else data->command = xstrdup(args->argv[0]); + data->squash_groups = !args_has(args, 'G'); data->data = mode_tree_start(wp, args, window_tree_build, window_tree_draw, window_tree_search, data, window_tree_sort_list, |