Hello.
I've been using tmux for a while now and I think it's great.
Often, when working with it, I will accumulate too many windows and
then close some, leaving my numbers out of sequence.
I went to implement renumbering in tmux only to discover that it was
already present (session_renumber_windows), but not reachable directly
from a command.
The attached patch proposes adding a command which just calls
session_renumber_windows for a target session or all sessions.
I have tested it, and it appears to work alright (it applies against be6dc83).
Please let me know if you think this is worth applying, or if there's
already an easier way to accomplish this.
Thanks,
--max
diff --git a/Makefile.am b/Makefile.am
index 63e20b1..b1d18df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -105,6 +105,7 @@ dist_tmux_SOURCES = \
cmd-refresh-client.c \
cmd-rename-session.c \
cmd-rename-window.c \
+ cmd-renumber-windows.c \
cmd-resize-pane.c \
cmd-respawn-pane.c \
cmd-respawn-window.c \
diff --git a/cmd-renumber-windows.c b/cmd-renumber-windows.c
new file mode 100644
index 0000000..b8adeff
--- /dev/null
+++ b/cmd-renumber-windows.c
@@ -0,0 +1,40 @@
+#include <sys/types.h>
+
+#include <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Renumber windows.
+ */
+
+enum cmd_retval cmd_renumber_windows_exec(struct cmd *, struct cmd_q *);
+
+const struct cmd_entry cmd_renumber_windows_entry = {
+ "renumber-windows", "renumws",
+ "at:", 0, 0,
+ "[-a] " CMD_TARGET_SESSION_USAGE,
+ 0,
+ cmd_renumber_windows_exec
+};
+
+enum cmd_retval cmd_renumber_windows_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+ struct session *s, *s2, *s3;
+
+ if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
+ return (CMD_RETURN_ERROR);
+
+ if (args_has(args, 'a')) {
+ RB_FOREACH_SAFE(s2, sessions, &sessions, s3) {
+ if (s != s2) {
+ session_renumber_windows(s);
+ }
+ }
+ } else {
+ session_renumber_windows(s);
+ }
+
+ return (CMD_RETURN_NORMAL);
+}
diff --git a/cmd.c b/cmd.c
index eeffe4c..8f9da7c 100644
--- a/cmd.c
+++ b/cmd.c
@@ -81,6 +81,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_refresh_client_entry,
&cmd_rename_session_entry,
&cmd_rename_window_entry,
+ &cmd_renumber_windows_entry,
&cmd_resize_pane_entry,
&cmd_respawn_pane_entry,
&cmd_respawn_window_entry,
diff --git a/key-bindings.c b/key-bindings.c
index 00f73d7..1dbbbe9 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -129,6 +129,7 @@ key_bindings_init(void)
"bind p previous-window",
"bind q display-panes",
"bind r refresh-client",
+ "bind R renumber-windows",
"bind s choose-tree",
"bind t clock-mode",
"bind w choose-window",
diff --git a/tmux.h b/tmux.h
index e296ac7..948e840 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1782,6 +1782,7 @@ extern const struct cmd_entry cmd_previous_window_entry;
extern const struct cmd_entry cmd_refresh_client_entry;
extern const struct cmd_entry cmd_rename_session_entry;
extern const struct cmd_entry cmd_rename_window_entry;
+extern const struct cmd_entry cmd_renumber_windows_entry;
extern const struct cmd_entry cmd_resize_pane_entry;
extern const struct cmd_entry cmd_respawn_pane_entry;
extern const struct cmd_entry cmd_respawn_window_entry;
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users