From b38aa7120f63ffa2b77e984b97a2b1091d2bf2d4 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 9 Jun 2017 15:29:15 +0000 Subject: [PATCH] Add -O option to choose-* to set initial sort order. --- usr.bin/tmux/cmd-choose-tree.c | 14 +++++++------- usr.bin/tmux/mode-tree.c | 17 ++++++++++++++--- usr.bin/tmux/tmux.1 | 24 +++++++++++++++++++++++- usr.bin/tmux/tmux.h | 4 ++-- usr.bin/tmux/window-buffer.c | 4 ++-- usr.bin/tmux/window-client.c | 8 ++++---- usr.bin/tmux/window-tree.c | 6 +++--- 7 files changed, 55 insertions(+), 22 deletions(-) diff --git a/usr.bin/tmux/cmd-choose-tree.c b/usr.bin/tmux/cmd-choose-tree.c index 354fa910f87..a8268ff4fa3 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.35 2017/05/30 21:44:59 nicm Exp $ */ +/* $OpenBSD: cmd-choose-tree.c,v 1.36 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2012 Thomas Adam @@ -30,8 +30,8 @@ const struct cmd_entry cmd_choose_tree_entry = { .name = "choose-tree", .alias = NULL, - .args = { "st:w", 0, 1 }, - .usage = "[-sw] " CMD_TARGET_PANE_USAGE, + .args = { "O:st:w", 0, 1 }, + .usage = "[-sw] [-O sort-order] " CMD_TARGET_PANE_USAGE, .target = { 't', CMD_FIND_PANE, 0 }, @@ -43,8 +43,8 @@ const struct cmd_entry cmd_choose_client_entry = { .name = "choose-client", .alias = NULL, - .args = { "t:", 0, 1 }, - .usage = CMD_TARGET_PANE_USAGE, + .args = { "O:t:", 0, 1 }, + .usage = "[-O sort-order] " CMD_TARGET_PANE_USAGE, .target = { 't', CMD_FIND_PANE, 0 }, @@ -56,8 +56,8 @@ const struct cmd_entry cmd_choose_buffer_entry = { .name = "choose-buffer", .alias = NULL, - .args = { "t:", 0, 1 }, - .usage = CMD_TARGET_PANE_USAGE, + .args = { "O:t:", 0, 1 }, + .usage = "[-O sort-order] " CMD_TARGET_PANE_USAGE, .target = { 't', CMD_FIND_PANE, 0 }, diff --git a/usr.bin/tmux/mode-tree.c b/usr.bin/tmux/mode-tree.c index 49a123daff3..b9ffe63a931 100644 --- a/usr.bin/tmux/mode-tree.c +++ b/usr.bin/tmux/mode-tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mode-tree.c,v 1.4 2017/06/07 15:27:46 nicm Exp $ */ +/* $OpenBSD: mode-tree.c,v 1.5 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -273,12 +273,15 @@ mode_tree_each_tagged(struct mode_tree_data *mtd, void (*cb)(void *, void *, } struct mode_tree_data * -mode_tree_start(struct window_pane *wp, void (*buildcb)(void *, u_int, - uint64_t *), struct screen *(*drawcb)(void *, void *, u_int, u_int), +mode_tree_start(struct window_pane *wp, struct args *args, + void (*buildcb)(void *, u_int, uint64_t *), + struct screen *(*drawcb)(void *, void *, u_int, u_int), int (*searchcb)(void *, void *, const char *), void *modedata, const char **sort_list, u_int sort_size, struct screen **s) { struct mode_tree_data *mtd; + const char *sort; + u_int i; mtd = xcalloc(1, sizeof *mtd); mtd->references = 1; @@ -290,6 +293,14 @@ mode_tree_start(struct window_pane *wp, void (*buildcb)(void *, u_int, mtd->sort_size = sort_size; mtd->sort_type = 0; + sort = args_get(args, 'O'); + if (sort != NULL) { + for (i = 0; i < sort_size; i++) { + if (strcasecmp(sort, sort_list[i]) == 0) + mtd->sort_type = i; + } + } + mtd->buildcb = buildcb; mtd->drawcb = drawcb; mtd->searchcb = searchcb; diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 27eedebede3..310640a8248 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.560 2017/06/09 09:21:24 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.561 2017/06/09 15:29:15 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -1354,6 +1354,7 @@ the end of the visible pane. The default is to capture only the visible contents of the pane. .It Xo .Ic choose-client +.Op Fl O Ar sort-order .Op Fl t Ar target-pane .Op Ar template .Xc @@ -1389,10 +1390,18 @@ If .Ar template is not given, "detach-client -t '%%'" is used. .Pp +.Fl O +specifies the initial sort order: one of +.Ql name , +.Ql size , +.Ql creation , +or +.Ql activity . This command works only if at least one client is attached. .It Xo .Ic choose-tree .Op Fl sw +.Op Fl O Ar sort-order .Op Fl t Ar target-pane .Op Ar template .Xc @@ -1428,6 +1437,12 @@ If .Ar template is not given, "switch-client -t '%%'" is used. .Pp +.Fl O +specifies the initial sort order: one of +.Ql index , +.Ql name , +or +.Ql time . This command works only if at least one client is attached. .It Xo .Ic display-panes @@ -3957,6 +3972,7 @@ The buffer commands are as follows: .Bl -tag -width Ds .It Xo .Ic choose-buffer +.Op Fl O Ar sort-order .Op Fl t Ar target-pane .Op Ar template .Xc @@ -3988,6 +4004,12 @@ If .Ar template is not given, "paste-buffer -b '%%'" is used. .Pp +.Fl O +specifies the initial sort order: one of +.Ql time , +.Ql name +or +.Ql size . This command works only if at least one client is attached. .It Ic clear-history Op Fl t Ar target-pane .D1 (alias: Ic clearhist ) diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 346fefe3876..00b1ad9fa2d 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.783 2017/06/07 15:27:46 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.784 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -2201,7 +2201,7 @@ void mode_tree_each_tagged(struct mode_tree_data *, void (*)(void *, void *, key_code), key_code, int); void mode_tree_up(struct mode_tree_data *, int); void mode_tree_down(struct mode_tree_data *, int); -struct mode_tree_data *mode_tree_start(struct window_pane *, +struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *, void (*)(void *, u_int, uint64_t *), struct screen *(*)(void *, void *, u_int, u_int), int (*)(void *, void *, const char *), void *, const char **, u_int, struct screen **); diff --git a/usr.bin/tmux/window-buffer.c b/usr.bin/tmux/window-buffer.c index 17d9c8be9f9..12995e64695 100644 --- a/usr.bin/tmux/window-buffer.c +++ b/usr.bin/tmux/window-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-buffer.c,v 1.6 2017/06/09 15:17:20 nicm Exp $ */ +/* $OpenBSD: window-buffer.c,v 1.7 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -257,7 +257,7 @@ window_buffer_init(struct window_pane *wp, __unused struct cmd_find_state *fs, else data->command = xstrdup(args->argv[0]); - data->data = mode_tree_start(wp, window_buffer_build, + data->data = mode_tree_start(wp, args, window_buffer_build, window_buffer_draw, window_buffer_search, data, window_buffer_sort_list, nitems(window_buffer_sort_list), &s); diff --git a/usr.bin/tmux/window-client.c b/usr.bin/tmux/window-client.c index 3aa67ef3f63..e3feb401446 100644 --- a/usr.bin/tmux/window-client.c +++ b/usr.bin/tmux/window-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-client.c,v 1.4 2017/06/08 07:48:04 nicm Exp $ */ +/* $OpenBSD: window-client.c,v 1.5 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -54,8 +54,8 @@ enum window_client_sort_type { static const char *window_client_sort_list[] = { "name", "size", - "creation time", - "activity time" + "creation", + "activity" }; struct window_client_itemdata { @@ -247,7 +247,7 @@ window_client_init(struct window_pane *wp, __unused struct cmd_find_state *fs, else data->command = xstrdup(args->argv[0]); - data->data = mode_tree_start(wp, window_client_build, + data->data = mode_tree_start(wp, args, window_client_build, window_client_draw, NULL, data, window_client_sort_list, nitems(window_client_sort_list), &s); diff --git a/usr.bin/tmux/window-tree.c b/usr.bin/tmux/window-tree.c index fea32793b0f..aed2e49e7bc 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.3 2017/06/07 14:37:30 nicm Exp $ */ +/* $OpenBSD: window-tree.c,v 1.4 2017/06/09 15:29:15 nicm Exp $ */ /* * Copyright (c) 2017 Nicholas Marriott @@ -503,8 +503,8 @@ window_tree_init(struct window_pane *wp, struct cmd_find_state *fs, else data->command = xstrdup(args->argv[0]); - data->data = mode_tree_start(wp, window_tree_build, window_tree_draw, - window_tree_search, data, window_tree_sort_list, + data->data = mode_tree_start(wp, args, window_tree_build, + window_tree_draw, window_tree_search, data, window_tree_sort_list, nitems(window_tree_sort_list), &s); mode_tree_build(data->data); -- 2.20.1