summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES7
-rw-r--r--GNUmakefile4
-rw-r--r--Makefile4
-rw-r--r--cmd-command-prompt.c4
-rw-r--r--cmd-move-window.c125
-rw-r--r--cmd-select-prompt.c90
-rw-r--r--cmd.c3
-rw-r--r--key-bindings.c3
-rw-r--r--tmux.h3
9 files changed, 232 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index d05b0b48..7d2cef9e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
25 June 2008
-* move-window command.
+* select-prompt command to allow a window to be selected at a prompt. Only
+ windows in the current session may be selected. Bound to ' by default.
+ Suggested by merdely.
+* move-window command. Requested by merdely.
* Support binding alt keys (prefixed with M-). Change default to use
C- for ctrl keys (^ is still accepted as an alternative).
* Slim down default key bindings: support lowercase only.
@@ -570,4 +573,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.143 2008-06-25 20:33:20 nicm Exp $
+$Id: CHANGES,v 1.144 2008-06-25 20:43:13 nicm Exp $
diff --git a/GNUmakefile b/GNUmakefile
index 12c96c9c..9667c202 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.34 2008-06-25 20:33:20 nicm Exp $
+# $Id: GNUmakefile,v 1.35 2008-06-25 20:43:13 nicm Exp $
.PHONY: clean
@@ -28,7 +28,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \
cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \
cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \
- cmd-list-commands.c cmd-move-window.c \
+ cmd-list-commands.c cmd-move-window.c cmd-select-prompt.c \
window-scroll.c window-more.c window-copy.c options.c paste.c \
tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
diff --git a/Makefile b/Makefile
index dff27fb2..13c4bc3e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.67 2008-06-25 20:33:20 nicm Exp $
+# $Id: Makefile,v 1.68 2008-06-25 20:43:13 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@@ -32,7 +32,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-kill-server.c cmd-set-window-option.c cmd-show-options.c \
cmd-show-window-options.c cmd-command-prompt.c cmd-set-buffer.c \
cmd-show-buffer.c cmd-list-buffers.c cmd-delete-buffer.c \
- cmd-list-commands.c cmd-move-window.c \
+ cmd-list-commands.c cmd-move-window.c cmd-select-prompt.c \
window-scroll.c window-more.c window-copy.c options.c paste.c \
tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c
index 45592a70..c156002a 100644
--- a/cmd-command-prompt.c
+++ b/cmd-command-prompt.c
@@ -1,7 +1,7 @@
-/* $Id: cmd-command-prompt.c,v 1.3 2008-06-21 10:19:36 nicm Exp $ */
+/* $Id: cmd-command-prompt.c,v 1.4 2008-06-25 20:43:13 nicm Exp $ */
/*
- * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
+ * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
diff --git a/cmd-move-window.c b/cmd-move-window.c
new file mode 100644
index 00000000..31694443
--- /dev/null
+++ b/cmd-move-window.c
@@ -0,0 +1,125 @@
+/* $Id: cmd-move-window.c,v 1.1 2008-06-25 20:43:13 nicm Exp $ */
+
+/*
+ * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <getopt.h>
+#include <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Move a window.
+ */
+
+void cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_move_window_entry = {
+ "move-window", "movew",
+ "[-dk] " CMD_SRCDST_WINDOW_USAGE,
+ CMD_DFLAG|CMD_KFLAG,
+ cmd_srcdst_init,
+ cmd_srcdst_parse,
+ cmd_move_window_exec,
+ cmd_srcdst_send,
+ cmd_srcdst_recv,
+ cmd_srcdst_free,
+ cmd_srcdst_print
+};
+
+void
+cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_srcdst_data *data = self->data;
+ struct session *src, *dst;
+ struct winlink *wl_src, *wl_dst;
+ struct client *c;
+ u_int i;
+ int destroyed, idx;
+
+ if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
+ return;
+
+ if (arg_parse_window(data->dst, &dst, &idx) != 0) {
+ ctx->error(ctx, "bad window: %s", data->dst);
+ return;
+ }
+ if (dst == NULL)
+ dst = ctx->cursession;
+ if (dst == NULL)
+ dst = cmd_current_session(ctx);
+ if (dst == NULL) {
+ ctx->error(ctx, "session not found: %s", data->dst);
+ return;
+ }
+
+ wl_dst = NULL;
+ if (idx != -1)
+ wl_dst = winlink_find_by_index(&dst->windows, idx);
+ if (wl_dst != NULL) {
+ if (wl_dst->window == wl_src->window)
+ goto out;
+
+ if (data->flags & CMD_KFLAG) {
+ /*
+ * Can't use session_detach as it will destroy session
+ * if this makes it empty.
+ */
+ session_alert_cancel(dst, wl_dst);
+ winlink_remove(&dst->windows, wl_dst);
+
+ /* Force select/redraw if current. */
+ if (wl_dst == dst->curw) {
+ data->flags &= ~CMD_DFLAG;
+ dst->curw = NULL;
+ }
+ if (wl_dst == dst->lastw)
+ dst->lastw = NULL;
+ }
+ }
+
+ wl_dst = session_attach(dst, wl_src->window, idx);
+ if (wl_dst == NULL) {
+ ctx->error(ctx, "index in use: %d", idx);
+ return;
+ }
+
+ destroyed = session_detach(src, wl_src);
+ for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
+ c = ARRAY_ITEM(&clients, i);
+ if (c == NULL || c->session != src)
+ continue;
+ if (destroyed) {
+ c->session = NULL;
+ server_write_client(c, MSG_EXIT, NULL, 0);
+ } else
+ server_redraw_client(c);
+ }
+
+ if (data->flags & CMD_DFLAG)
+ server_status_session(dst);
+ else {
+ session_select(dst, wl_dst->idx);
+ server_redraw_session(dst);
+ }
+ recalculate_sizes();
+
+out:
+ if (ctx->cmdclient != NULL)
+ server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+}
diff --git a/cmd-select-prompt.c b/cmd-select-prompt.c
new file mode 100644
index 00000000..adeb5783
--- /dev/null
+++ b/cmd-select-prompt.c
@@ -0,0 +1,90 @@
+/* $Id: cmd-select-prompt.c,v 1.1 2008-06-25 20:43:13 nicm Exp $ */
+
+/*
+ * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stdlib.h>
+
+#include "tmux.h"
+
+/*
+ * Prompt for window index and select it.
+ */
+
+void cmd_select_prompt_exec(struct cmd *, struct cmd_ctx *);
+
+void cmd_select_prompt_callback(void *, char *);
+
+const struct cmd_entry cmd_select_prompt_entry = {
+ "select-prompt", NULL,
+ CMD_TARGET_CLIENT_USAGE,
+ 0,
+ cmd_target_init,
+ cmd_target_parse,
+ cmd_select_prompt_exec,
+ cmd_target_send,
+ cmd_target_recv,
+ cmd_target_free,
+ cmd_target_print
+};
+
+void
+cmd_select_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_target_data *data = self->data;
+ struct client *c;
+
+ if ((c = cmd_find_client(ctx, data->target)) == NULL)
+ return;
+
+ if (c->prompt_string != NULL)
+ return;
+
+ server_set_client_prompt(c, "'", cmd_select_prompt_callback, c);
+
+ if (ctx->cmdclient != NULL)
+ server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
+}
+
+void
+cmd_select_prompt_callback(void *data, char *s)
+{
+ struct client *c = data;
+ struct winlink *wl;
+ const char *errstr;
+ char msg[128];
+ u_int idx;
+
+ idx = strtonum(s, 0, UINT_MAX, &errstr);
+ if (errstr != NULL) {
+ xsnprintf(msg, sizeof msg, "Index %s: %s", errstr, s);
+ server_set_client_message(c, msg);
+ return;
+ }
+
+ if ((wl = winlink_find_by_index(&c->session->windows, idx)) == NULL) {
+ xsnprintf(msg, sizeof msg,
+ "Window not found: %s:%d", c->session->name, idx);
+ server_set_client_message(c, msg);
+ return;
+ }
+
+ if (session_select(c->session, idx) == 0)
+ server_redraw_session(c->session);
+ recalculate_sizes();
+}
diff --git a/cmd.c b/cmd.c
index 84947be3..9ae9848a 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.57 2008-06-25 20:33:20 nicm Exp $ */
+/* $Id: cmd.c,v 1.58 2008-06-25 20:43:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -55,6 +55,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_rename_session_entry,
&cmd_rename_window_entry,
&cmd_scroll_mode_entry,
+ &cmd_select_prompt_entry,
&cmd_select_window_entry,
&cmd_send_keys_entry,
&cmd_send_prefix_entry,
diff --git a/key-bindings.c b/key-bindings.c
index ca862514..fe658e53 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -1,4 +1,4 @@
-/* $Id: key-bindings.c,v 1.36 2008-06-25 19:18:20 nicm Exp $ */
+/* $Id: key-bindings.c,v 1.37 2008-06-25 20:43:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -103,6 +103,7 @@ key_bindings_init(void)
{ 'r', &cmd_refresh_client_entry },
{ 's', &cmd_list_sessions_entry },
{ 'w', &cmd_list_windows_entry },
+ { '\'', &cmd_select_prompt_entry },
{ META, &cmd_send_prefix_entry },
};
u_int i;
diff --git a/tmux.h b/tmux.h
index 80342d11..15d5cb8e 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.169 2008-06-25 20:33:20 nicm Exp $ */
+/* $Id: tmux.h,v 1.170 2008-06-25 20:43:14 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -971,6 +971,7 @@ extern const struct cmd_entry cmd_scroll_mode_entry;
extern const struct cmd_entry cmd_select_window_entry;
extern const struct cmd_entry cmd_send_keys_entry;
extern const struct cmd_entry cmd_send_prefix_entry;
+extern const struct cmd_entry cmd_select_prompt_entry;
extern const struct cmd_entry cmd_set_buffer_entry;
extern const struct cmd_entry cmd_set_option_entry;
extern const struct cmd_entry cmd_set_window_option_entry;