load-buffer command

This commit is contained in:
Tiago Cunha 2009-01-25 19:00:10 +00:00
parent d60ad6f483
commit f62ed6aaa3
9 changed files with 126 additions and 11 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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 \

1
TODO
View File

@ -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

102
cmd-load-buffer.c Normal file
View File

@ -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);
}

3
cmd.c
View File

@ -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,

View File

@ -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

10
tmux.1
View File

@ -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 )

3
tmux.h
View File

@ -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;