summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2020-06-13 09:05:53 +0000
committernicm <nicm@openbsd.org>2020-06-13 09:05:53 +0000
commit4f91c93509bdc1be6b5c071e077134971826656c (patch)
tree931b106fc49a59f2c62da747338349f0b9a73db2
parentSome new firmware for ConnectX-5 tries to give pages back when (diff)
downloadwireguard-openbsd-4f91c93509bdc1be6b5c071e077134971826656c.tar.xz
wireguard-openbsd-4f91c93509bdc1be6b5c071e077134971826656c.zip
Add -b flags to insert a window before (like the existing -a for after)
to break-pane, move-window, new-window. GitHub issue 2261.
-rw-r--r--usr.bin/tmux/cmd-break-pane.c18
-rw-r--r--usr.bin/tmux/cmd-move-window.c19
-rw-r--r--usr.bin/tmux/cmd-new-window.c18
-rw-r--r--usr.bin/tmux/tmux.137
-rw-r--r--usr.bin/tmux/tmux.h4
-rw-r--r--usr.bin/tmux/window.c14
6 files changed, 63 insertions, 47 deletions
diff --git a/usr.bin/tmux/cmd-break-pane.c b/usr.bin/tmux/cmd-break-pane.c
index 8865abd6b03..4c248a2080b 100644
--- a/usr.bin/tmux/cmd-break-pane.c
+++ b/usr.bin/tmux/cmd-break-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-break-pane.c,v 1.58 2020/05/26 09:01:03 nicm Exp $ */
+/* $OpenBSD: cmd-break-pane.c,v 1.59 2020/06/13 09:05:53 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -34,8 +34,8 @@ const struct cmd_entry cmd_break_pane_entry = {
.name = "break-pane",
.alias = "breakp",
- .args = { "adPF:n:s:t:", 0, 0 },
- .usage = "[-adP] [-F format] [-n window-name] [-s src-pane] "
+ .args = { "abdPF:n:s:t:", 0, 0 },
+ .usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
"[-t dst-window]",
.source = { 's', CMD_FIND_PANE, 0 },
@@ -58,16 +58,16 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
struct session *dst_s = target->s;
struct window_pane *wp = source->wp;
struct window *w = wl->window;
- char *name, *cause;
- int idx = target->idx;
+ char *name, *cause, *cp;
+ int idx = target->idx, before;
const char *template;
- char *cp;
- if (args_has(args, 'a')) {
+ before = args_has(args, 'b');
+ if (args_has(args, 'a') || before) {
if (target->wl != NULL)
- idx = winlink_shuffle_up(dst_s, target->wl);
+ idx = winlink_shuffle_up(dst_s, target->wl, before);
else
- idx = winlink_shuffle_up(dst_s, dst_s->curw);
+ idx = winlink_shuffle_up(dst_s, dst_s->curw, before);
if (idx == -1)
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-move-window.c b/usr.bin/tmux/cmd-move-window.c
index c5df28f4fda..efbc3255311 100644
--- a/usr.bin/tmux/cmd-move-window.c
+++ b/usr.bin/tmux/cmd-move-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-move-window.c,v 1.32 2020/04/22 21:15:33 nicm Exp $ */
+/* $OpenBSD: cmd-move-window.c,v 1.33 2020/06/13 09:05:53 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -32,8 +32,8 @@ const struct cmd_entry cmd_move_window_entry = {
.name = "move-window",
.alias = "movew",
- .args = { "adkrs:t:", 0, 0 },
- .usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
+ .args = { "abdkrs:t:", 0, 0 },
+ .usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
.source = { 's', CMD_FIND_WINDOW, 0 },
/* -t is special */
@@ -46,8 +46,8 @@ const struct cmd_entry cmd_link_window_entry = {
.name = "link-window",
.alias = "linkw",
- .args = { "adks:t:", 0, 0 },
- .usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
+ .args = { "abdks:t:", 0, 0 },
+ .usage = "[-abdk] " CMD_SRCDST_WINDOW_USAGE,
.source = { 's', CMD_FIND_WINDOW, 0 },
/* -t is special */
@@ -67,7 +67,7 @@ cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
struct session *dst;
struct winlink *wl = source->wl;
char *cause;
- int idx, kflag, dflag, sflag;
+ int idx, kflag, dflag, sflag, before;
if (args_has(args, 'r')) {
if (cmd_find_target(&target, item, tflag, CMD_FIND_SESSION,
@@ -90,11 +90,12 @@ cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
dflag = args_has(args, 'd');
sflag = args_has(args, 's');
- if (args_has(args, 'a')) {
+ before = args_has(args, 'b');
+ if (args_has(args, 'a') || before) {
if (target.wl != NULL)
- idx = winlink_shuffle_up(dst, target.wl);
+ idx = winlink_shuffle_up(dst, target.wl, before);
else
- idx = winlink_shuffle_up(dst, dst->curw);
+ idx = winlink_shuffle_up(dst, dst->curw, before);
if (idx == -1)
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index 954950be50d..a09e872ddea 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.87 2020/04/13 20:51:57 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.88 2020/06/13 09:05:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_new_window_entry = {
.name = "new-window",
.alias = "neww",
- .args = { "ac:de:F:kn:Pt:", 0, -1 },
- .usage = "[-adkP] [-c start-directory] [-e environment] [-F format] "
+ .args = { "abc:de:F:kn:Pt:", 0, -1 },
+ .usage = "[-abdkP] [-c start-directory] [-e environment] [-F format] "
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [command]",
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
@@ -58,16 +58,20 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item);
struct session *s = target->s;
struct winlink *wl = target->wl;
- int idx = target->idx;
+ int idx = target->idx, before;
struct winlink *new_wl;
char *cause = NULL, *cp;
const char *template, *add;
struct cmd_find_state fs;
struct args_value *value;
- if (args_has(args, 'a') && (idx = winlink_shuffle_up(s, wl)) == -1) {
- cmdq_error(item, "couldn't get a window index");
- return (CMD_RETURN_ERROR);
+ before = args_has(args, 'b');
+ if (args_has(args, 'a') || before) {
+ idx = winlink_shuffle_up(s, wl, before);
+ if (idx == -1) {
+ cmdq_error(item, "couldn't get a window index");
+ return (CMD_RETURN_ERROR);
+ }
}
memset(&sc, 0, sizeof sc);
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index ad122983251..fa54eefaeeb 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.783 2020/06/12 07:52:38 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.784 2020/06/13 09:05:53 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: June 12 2020 $
+.Dd $Mdocdate: June 13 2020 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1792,7 +1792,7 @@ from which the layout was originally defined.
Commands related to windows and panes are as follows:
.Bl -tag -width Ds
.It Xo Ic break-pane
-.Op Fl adP
+.Op Fl abdP
.Op Fl F Ar format
.Op Fl n Ar window-name
.Op Fl s Ar src-pane
@@ -1804,9 +1804,11 @@ Break
off from its containing window to make it the only pane in
.Ar dst-window .
With
-.Fl a ,
-the window is moved to the next index up (following windows
-are moved if necessary).
+.Fl a
+or
+.Fl b ,
+the window is moved to the next index after or before (existing windows are
+moved if necessary).
If
.Fl d
is given, the new window does not become the current window.
@@ -2188,7 +2190,7 @@ If no
.Ar target-session
is specified, select the last window of the current session.
.It Xo Ic link-window
-.Op Fl adk
+.Op Fl abdk
.Op Fl s Ar src-window
.Op Fl t Ar dst-window
.Xc
@@ -2203,9 +2205,12 @@ is specified and no such window exists, the
.Ar src-window
is linked there.
With
-.Fl a ,
-the window is moved to the next index up (following windows
-are moved if necessary).
+.Fl a
+or
+.Fl b
+the window is moved to the next index after or before
+.Ar dst-window
+(existing windows are moved if necessary).
If
.Fl k
is given and
@@ -2272,7 +2277,7 @@ section.
Does the same as
.Ic join-pane .
.It Xo Ic move-window
-.Op Fl ardk
+.Op Fl abrdk
.Op Fl s Ar src-window
.Op Fl t Ar dst-window
.Xc
@@ -2290,7 +2295,7 @@ the
.Ic base-index
option.
.It Xo Ic new-window
-.Op Fl adkP
+.Op Fl abdkP
.Op Fl c Ar start-directory
.Op Fl e Ar environment
.Op Fl F Ar format
@@ -2301,10 +2306,12 @@ option.
.D1 (alias: Ic neww )
Create a new window.
With
-.Fl a ,
-the new window is inserted at the next index up from the specified
+.Fl a
+or
+.Fl b ,
+the new window is inserted at the next index after or before the specified
.Ar target-window ,
-moving windows up if necessary,
+moving windows up if necessary;
otherwise
.Ar target-window
is the new window location.
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a3f9ab2473d..1958a400101 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1068 2020/06/11 19:43:34 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1069 2020/06/13 09:05:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2720,7 +2720,7 @@ void window_set_name(struct window *, const char *);
void window_add_ref(struct window *, const char *);
void window_remove_ref(struct window *, const char *);
void winlink_clear_flags(struct winlink *);
-int winlink_shuffle_up(struct session *, struct winlink *);
+int winlink_shuffle_up(struct session *, struct winlink *, int);
int window_pane_start_input(struct window_pane *,
struct cmdq_item *, char **);
void *window_pane_get_new_data(struct window_pane *,
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index d4c64e4cf87..ea2cf05a4b9 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.265 2020/06/05 11:20:51 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.266 2020/06/13 09:05:53 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1490,13 +1490,16 @@ winlink_clear_flags(struct winlink *wl)
/* Shuffle window indexes up. */
int
-winlink_shuffle_up(struct session *s, struct winlink *wl)
+winlink_shuffle_up(struct session *s, struct winlink *wl, int before)
{
int idx, last;
if (wl == NULL)
return (-1);
- idx = wl->idx + 1;
+ if (before)
+ idx = wl->idx;
+ else
+ idx = wl->idx + 1;
/* Find the next free index. */
for (last = idx; last < INT_MAX; last++) {
@@ -1509,8 +1512,9 @@ winlink_shuffle_up(struct session *s, struct winlink *wl)
/* Move everything from last - 1 to idx up a bit. */
for (; last > idx; last--) {
wl = winlink_find_by_index(&s->windows, last - 1);
- server_link_window(s, wl, s, last, 0, 0, NULL);
- server_unlink_window(s, wl);
+ RB_REMOVE(winlinks, &s->windows, wl);
+ wl->idx++;
+ RB_INSERT(winlinks, &s->windows, wl);
}
return (idx);