summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-01-25 19:00:10 +0000
committerTiago Cunha <tcunha@gmx.com>2009-01-25 19:00:10 +0000
commitf62ed6aaa3db43e521e9a3f268d32a93ce20a271 (patch)
treed96cb4d32cb7cb11865f4bb9cad252e8f21738f5
parentd60ad6f483ddbe8ee2458aaef37b6f38140d63f5 (diff)
load-buffer command
-rw-r--r--CHANGES6
-rw-r--r--GNUmakefile4
-rw-r--r--Makefile4
-rw-r--r--TODO1
-rw-r--r--cmd-load-buffer.c102
-rw-r--r--cmd.c3
-rw-r--r--examples/tmux.vim4
-rw-r--r--tmux.110
-rw-r--r--tmux.h3
9 files changed, 126 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index 18b4b3c8..dbddb9d6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+25 January 2009
+
+* load-buffer command
+
23 January 2009
* Use reverse colours rather than swapping fg and bg for message, mode and
@@ -1004,7 +1008,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.233 2009-01-23 20:53:18 nicm Exp $
+$Id: CHANGES,v 1.234 2009-01-25 19:00:10 tcunha Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
diff --git a/GNUmakefile b/GNUmakefile
index 65520f75..e7f53913 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.66 2009-01-21 17:45:19 nicm Exp $
+# $Id: GNUmakefile,v 1.67 2009-01-25 19:00:10 tcunha Exp $
.PHONY: clean
@@ -36,7 +36,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
- cmd-suspend-client.c cmd-find-window.c \
+ cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \
window-clock.c window-scroll.c window-more.c window-copy.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
diff --git a/Makefile b/Makefile
index 40d7098a..a5d3eee7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.105 2009-01-21 17:45:19 nicm Exp $
+# $Id: Makefile,v 1.106 2009-01-25 19:00:10 tcunha Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@@ -39,7 +39,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-save-buffer.c cmd-select-pane.c cmd-split-window.c \
cmd-resize-pane-up.c cmd-resize-pane-down.c cmd-kill-pane.c \
cmd-up-pane.c cmd-down-pane.c cmd-choose-window.c cmd-choose-session.c \
- cmd-suspend-client.c cmd-find-window.c \
+ cmd-suspend-client.c cmd-find-window.c cmd-load-buffer.c \
window-clock.c window-scroll.c window-more.c window-copy.c \
window-choose.c \
options.c options-cmd.c paste.c colour.c utf8.c clock.c \
diff --git a/TODO b/TODO
index 7fe47aca..beae370d 100644
--- a/TODO
+++ b/TODO
@@ -75,7 +75,6 @@
(hopefully) for 0.7, in no particular order:
- swap-pane-up, swap-pane-down (maybe move-pane-*)
- move-pane (to window) (maybe break-pane?)
-- command: load-buffer -b number filename
- command: copy-buffer -s src-session -t dst-session -a src-index -b dst-index
(copy from other session)
- flag to scroll-mode/copy-mode to automatically scroll up a page
diff --git a/cmd-load-buffer.c b/cmd-load-buffer.c
new file mode 100644
index 00000000..f10cf255
--- /dev/null
+++ b/cmd-load-buffer.c
@@ -0,0 +1,102 @@
+/* $Id: cmd-load-buffer.c,v 1.1 2009-01-25 19:00:10 tcunha Exp $ */
+
+/*
+ * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
+ *
+ * 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 <sys/stat.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "tmux.h"
+
+/*
+ * Loads a session paste buffer from a file.
+ */
+
+int cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_load_buffer_entry = {
+ "load-buffer", "loadb",
+ CMD_BUFFER_SESSION_USAGE " path",
+ CMD_ARG1,
+ cmd_buffer_init,
+ cmd_buffer_parse,
+ cmd_load_buffer_exec,
+ cmd_buffer_send,
+ cmd_buffer_recv,
+ cmd_buffer_free,
+ cmd_buffer_print
+};
+
+int
+cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_buffer_data *data = self->data;
+ struct session *s;
+ struct stat statbuf;
+ FILE *f;
+ char *buf;
+ u_int limit;
+
+ if ((s = cmd_find_session(ctx, data->target)) == NULL)
+ return (-1);
+
+ if (stat(data->arg, &statbuf) < 0) {
+ ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
+ return (-1);
+ }
+
+ if ((f = fopen(data->arg, "r")) == NULL) {
+ ctx->error(ctx, "%s: %s", data->arg, strerror(errno));
+ return (-1);
+ }
+
+ /*
+ * We don't want to die due to memory exhaustion, hence xmalloc can't
+ * be used here.
+ */
+ if ((buf = malloc(statbuf.st_size + 1)) == NULL) {
+ ctx->error(ctx, "malloc error: %s", strerror(errno));
+ return (-1);
+ }
+
+ if (fread(buf, 1, statbuf.st_size, f) != statbuf.st_size) {
+ ctx->error(ctx, "%s: fread error", data->arg);
+ xfree(buf);
+ fclose(f);
+ return (-1);
+ }
+
+ buf[statbuf.st_size] = '\0';
+ fclose(f);
+
+ limit = options_get_number(&s->options, "buffer-limit");
+ if (data->buffer == -1) {
+ paste_add(&s->buffers, buf, limit);
+ return (0);
+ }
+ if (paste_replace(&s->buffers, data->buffer, buf) != 0) {
+ ctx->error(ctx, "no buffer %d", data->buffer);
+ xfree(buf);
+ return (-1);
+ }
+
+ return (0);
+}
diff --git a/cmd.c b/cmd.c
index 97a097d9..72a8e00b 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.83 2009-01-19 18:23:40 nicm Exp $ */
+/* $Id: cmd.c,v 1.84 2009-01-25 19:00:10 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -50,6 +50,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_list_keys_entry,
&cmd_list_sessions_entry,
&cmd_list_windows_entry,
+ &cmd_load_buffer_entry,
&cmd_lock_server_entry,
&cmd_move_window_entry,
&cmd_new_session_entry,
diff --git a/examples/tmux.vim b/examples/tmux.vim
index 31067e41..04e4d298 100644
--- a/examples/tmux.vim
+++ b/examples/tmux.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: tmux(1) configuration file
" Maintainer: Tiago Cunha <me@tiagocunha.org>
-" Last Change: $Date: 2009-01-17 18:00:24 $
+" Last Change: $Date: 2009-01-25 19:00:10 $
if version < 600
syntax clear
@@ -33,7 +33,7 @@ syn keyword tmuxCmds source[-file] info server-info clock-mode lock[-server]
syn keyword tmuxCmds pass set-password saveb save-buffer downp down-pane killp
syn keyword tmuxCmds kill-pane resizep-down resize-pane-down resizep-up
syn keyword tmuxCmds resize-pane-up selectp select-pane splitw split-window
-syn keyword tmuxCmds upp up-pane choose-session choose-window
+syn keyword tmuxCmds upp up-pane choose-session choose-window loadb load-buffer
syn keyword tmuxOptsSet prefix status status-fg status-bg bell-action
syn keyword tmuxOptsSet default-command history-limit status-left status-right
diff --git a/tmux.1 b/tmux.1
index 08eaf35b..82f236a3 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1,4 +1,4 @@
-.\" $Id: tmux.1,v 1.68 2009-01-20 20:03:13 nicm Exp $
+.\" $Id: tmux.1,v 1.69 2009-01-25 19:00:10 tcunha Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -507,6 +507,14 @@ List all sessions managed by the server.
.D1 (alias: Ic lsw )
List windows in the current session or in
.Ar target-session .
+.It Xo Ic load-buffer
+.Op Fl b Ar buffer-index
+.Op Fl t Ar target-session
+.Ar path
+.Xc
+.D1 (alias: Ic loadb )
+Load the contents of the specified paste buffer from
+.Ar path .
.It Xo Ic lock-server
.Xc
.D1 (alias: Ic lock )
diff --git a/tmux.h b/tmux.h
index f2bb8c12..4a018911 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.249 2009-01-25 18:51:28 tcunha Exp $ */
+/* $Id: tmux.h,v 1.250 2009-01-25 19:00:10 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1124,6 +1124,7 @@ extern const struct cmd_entry cmd_list_commands_entry;
extern const struct cmd_entry cmd_list_keys_entry;
extern const struct cmd_entry cmd_list_sessions_entry;
extern const struct cmd_entry cmd_list_windows_entry;
+extern const struct cmd_entry cmd_load_buffer_entry;
extern const struct cmd_entry cmd_lock_server_entry;
extern const struct cmd_entry cmd_move_window_entry;
extern const struct cmd_entry cmd_new_session_entry;