Add sort order flags to switch-mode, GitHub issue 5696 from harikp2002

at gmail dot com.
This commit is contained in:
nicm
2026-10-07 13:13:49 +00:00
committed by tmux update bot
parent ddd0698e30
commit f7195bec82
3 changed files with 34 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: cmd-choose-tree.c,v 1.58 2026/07/14 17:17:17 nicm Exp $ */
/* $OpenBSD: cmd-choose-tree.c,v 1.59 2026/10/07 13:13:49 nicm Exp $ */
/*
* Copyright (c) 2012 Thomas Adam <thomas@xteddy.org>
@@ -88,8 +88,9 @@ const struct cmd_entry cmd_switch_mode_entry = {
.name = "switch-mode",
.alias = NULL,
.args = { "F:kst:wZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-kswZ] [-F format] " CMD_TARGET_PANE_USAGE " [command]",
.args = { "F:kO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-krsZw] [-F format] [-O sort-order] " CMD_TARGET_PANE_USAGE
" [command]",
.target = { 't', CMD_FIND_PANE, 0 },

14
tmux.1
View File

@@ -1,4 +1,4 @@
.\" $OpenBSD: tmux.1,v 1.1179 2026/10/07 12:59:50 nicm Exp $
.\" $OpenBSD: tmux.1,v 1.1180 2026/10/07 13:13:49 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -3131,8 +3131,9 @@ The
command works only if at least one client is attached.
.It Xo
.Ic switch\-mode
.Op Fl kswZ
.Op Fl krsZw
.Op Fl F Ar format
.Op Fl O Ar sort\-order
.Op Fl t Ar target\-pane
.Op Ar command
.Xc
@@ -3145,6 +3146,15 @@ matching and only matching items are shown, sorted by how well they match.
lists sessions (the default) and
.Fl w
lists windows.
.Fl O
specifies the initial sort order within matches of equal quality: one of
.Ql index ,
.Ql name ,
or
.Ql activity
(time).
.Fl r
reverses the sort order.
.Fl Z
zooms the pane.
The following keys may be used in switch mode:

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: window-switch.c,v 1.4 2026/09/01 21:03:55 nicm Exp $ */
/* $OpenBSD: window-switch.c,v 1.5 2026/10/07 13:13:49 nicm Exp $ */
/*
* Copyright (c) 2026 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -88,6 +88,8 @@ struct window_switch_modedata {
char *command;
enum window_switch_type type;
enum sort_order order;
int reversed;
char *filter;
struct prompt *prompt;
u_int prompt_cx;
@@ -191,8 +193,9 @@ window_switch_build(struct window_switch_modedata *data)
struct winlink **wl;
struct sort_criteria sort_crit;
sort_crit.order = SORT_NAME;
sort_crit.reversed = 0;
sort_crit.order = data->order;
sort_crit.reversed = data->reversed;
sort_crit.order_seq = NULL;
for (i = 0; i < data->item_size; i++)
window_switch_free_item(data->item_list[i]);
@@ -346,6 +349,18 @@ window_switch_init(struct window_mode_entry *wme,
wme->data = data = xcalloc(1, sizeof *data);
data->wp = wp;
data->order = SORT_NAME;
data->reversed = 0;
if (args != NULL) {
if (args_has(args, 'O')) {
data->order = sort_order_from_string(args_get(args, 'O'));
if (data->order == SORT_END)
data->order = SORT_NAME;
}
if (args_has(args, 'r'))
data->reversed = 1;
}
if (args_has(args, 'w'))
data->type = WINDOW_SWITCH_TYPE_WINDOW;
else