Implement some obvious missing sort orders, from Dane Jensen in GitHub

issue 4813.
This commit is contained in:
nicm
2026-02-10 09:55:53 +00:00
parent 5a33616e65
commit 25f6d8b1e9
4 changed files with 40 additions and 14 deletions

40
sort.c
View File

@@ -197,23 +197,25 @@ sort_pane_cmp(const void *a0, const void *b0)
case SORT_CREATION:
result = a->id - b->id;
break;
case SORT_INDEX:
case SORT_NAME:
case SORT_ORDER:
case SORT_SIZE:
case SORT_END:
result = a->sx * a->sy - b->sx * b->sy;
break;
}
if (result == 0) {
/*
* Panes don't have names, so use number order for any other
* sort field.
*/
case SORT_INDEX:
window_pane_index(a, &ai);
window_pane_index(b, &bi);
result = ai - bi;
break;
case SORT_NAME:
result = strcmp(a->screen->title, b->screen->title);
break;
case SORT_ORDER:
case SORT_END:
break;
}
if (result == 0)
result = strcmp(a->screen->title, b->screen->title);
if (sort_crit->reversed)
result = -result;
return (result);
@@ -235,6 +237,16 @@ sort_winlink_cmp(const void *a0, const void *b0)
case SORT_INDEX:
result = wla->idx - wlb->idx;
break;
case SORT_CREATION:
if (timercmp(&wa->creation_time, &wb->creation_time, >)) {
result = -1;
break;
}
if (timercmp(&wa->creation_time, &wb->creation_time, <)) {
result = 1;
break;
}
break;
case SORT_ACTIVITY:
if (timercmp(&wa->activity_time, &wb->activity_time, >)) {
result = -1;
@@ -248,9 +260,10 @@ sort_winlink_cmp(const void *a0, const void *b0)
case SORT_NAME:
result = strcmp(wa->name, wb->name);
break;
case SORT_CREATION:
case SORT_ORDER:
case SORT_SIZE:
result = wa->sx * wa->sy - wb->sx * wb->sy;
break;
case SORT_ORDER:
case SORT_END:
break;
}
@@ -295,7 +308,8 @@ sort_order_from_string(const char* order)
return (SORT_CREATION);
if (strcasecmp(order, "index") == 0)
return (SORT_INDEX);
if (strcasecmp(order, "name") == 0)
if (strcasecmp(order, "name") == 0 ||
strcasecmp(order, "title") == 0)
return (SORT_NAME);
if (strcasecmp(order, "order") == 0)
return (SORT_ORDER);

10
tmux.1
View File

@@ -3090,7 +3090,11 @@ See the
section.
.Fl O
specifies the sort order: one of
.Ql name ,
.Ql name
(title),
.Ql index ,
.Ql size
(area),
.Ql creation
(time), or
.Ql activity
@@ -3123,6 +3127,10 @@ section.
specifies the sort order: one of
.Ql index ,
.Ql name ,
.Ql size
(area),
.Ql creation
(time),
or
.Ql activity
(time).

1
tmux.h
View File

@@ -1254,6 +1254,7 @@ struct window {
struct event offset_timer;
struct timeval activity_time;
struct timeval creation_time;
struct window_pane *active;
struct window_panes last_panes;

View File

@@ -330,6 +330,9 @@ window_create(u_int sx, u_int sy, u_int xpixel, u_int ypixel)
RB_INSERT(windows, &windows, w);
window_set_fill_character(w);
if (gettimeofday(&w->creation_time, NULL) != 0)
fatal("gettimeofday failed");
window_update_activity(w);
log_debug("%s: @%u create %ux%u (%ux%u)", __func__, w->id, sx, sy,