diff --git a/CHANGES b/CHANGES index 7795f188..3b402477 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +09 November 2007 + +* (nicm) rename-session command. + 08 November 2007 * (nicm) Check for required terminal capabilities on start. @@ -190,4 +194,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.59 2007-11-08 10:39:52 nicm Exp $ +$Id: CHANGES,v 1.60 2007-11-09 11:02:01 nicm Exp $ diff --git a/GNUmakefile b/GNUmakefile index e532e756..af6c9343 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -# $Id: GNUmakefile,v 1.1 2007-10-31 14:26:26 nicm Exp $ +# $Id: GNUmakefile,v 1.2 2007-11-09 11:02:01 nicm Exp $ .PHONY: clean @@ -20,7 +20,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-set-option.c cmd-rename-window.c cmd-select-window.c \ cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \ cmd-refresh-session.c cmd-kill-window.c cmd-list-clients.c \ - cmd-has-session.c cmd-link-window.c cmd-unlink-window.c cmd-swap-window.c + cmd-has-session.c cmd-link-window.c cmd-unlink-window.c \ + cmd-swap-window.c cmd-rename-session.c CC?= gcc INCDIRS+= -I. -I- diff --git a/Makefile b/Makefile index df5b3d71..d55eb579 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.36 2007-10-31 14:26:26 nicm Exp $ +# $Id: Makefile,v 1.37 2007-11-09 11:02:01 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean @@ -24,7 +24,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-set-option.c cmd-rename-window.c cmd-select-window.c \ cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \ cmd-refresh-session.c cmd-kill-window.c cmd-list-clients.c \ - cmd-has-session.c cmd-link-window.c cmd-unlink-window.c cmd-swap-window.c + cmd-has-session.c cmd-link-window.c cmd-unlink-window.c \ + cmd-swap-window.c cmd-rename-session.c CC?= cc INCDIRS+= -I. -I- -I/usr/local/include diff --git a/TODO b/TODO index 8b2604c5..e32bd9d4 100644 --- a/TODO +++ b/TODO @@ -52,7 +52,6 @@ -- For 0.1 -------------------------------------------------------------------- - man page - commands: - rename sessions kill session (not bound by default) - fix most(1) problems after scrolling - fix mutt problems with redraw (mutt's) status line when reading mail diff --git a/cmd-rename-session.c b/cmd-rename-session.c new file mode 100644 index 00000000..9c44398a --- /dev/null +++ b/cmd-rename-session.c @@ -0,0 +1,126 @@ +/* $Id: cmd-rename-session.c,v 1.1 2007-11-09 11:02:01 nicm Exp $ */ + +/* + * Copyright (c) 2007 Nicholas Marriott + * + * 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 + +#include +#include + +#include "tmux.h" + +/* + * Change session name. + */ + +int cmd_rename_session_parse(void **, int, char **, char **); +void cmd_rename_session_exec(void *, struct cmd_ctx *); +void cmd_rename_session_send(void *, struct buffer *); +void cmd_rename_session_recv(void **, struct buffer *); +void cmd_rename_session_free(void *); + +struct cmd_rename_session_data { + char *newname; +}; + +const struct cmd_entry cmd_rename_session_entry = { + "rename-session", "rename", "new-name", + 0, + cmd_rename_session_parse, + cmd_rename_session_exec, + cmd_rename_session_send, + cmd_rename_session_recv, + cmd_rename_session_free +}; + +int +cmd_rename_session_parse(void **ptr, int argc, char **argv, char **cause) +{ + struct cmd_rename_session_data *data; + int opt; + + *ptr = data = xmalloc(sizeof *data); + data->newname = NULL; + + while ((opt = getopt(argc, argv, "")) != EOF) { + switch (opt) { + default: + goto usage; + } + } + argc -= optind; + argv += optind; + if (argc != 1) + goto usage; + + data->newname = xstrdup(argv[0]); + + return (0); + +usage: + usage(cause, "%s %s", + cmd_rename_session_entry.name, cmd_rename_session_entry.usage); + + cmd_rename_session_free(data); + return (-1); +} + +void +cmd_rename_session_exec(void *ptr, struct cmd_ctx *ctx) +{ + struct cmd_rename_session_data *data = ptr; + struct client *c = ctx->client; + struct session *s = ctx->session; + + if (data == NULL) + return; + + xfree(s->name); + s->name = xstrdup(data->newname); + + if (!(ctx->flags & CMD_KEY)) + server_write_client(c, MSG_EXIT, NULL, 0); +} + +void +cmd_rename_session_send(void *ptr, struct buffer *b) +{ + struct cmd_rename_session_data *data = ptr; + + buffer_write(b, data, sizeof *data); + cmd_send_string(b, data->newname); +} + +void +cmd_rename_session_recv(void **ptr, struct buffer *b) +{ + struct cmd_rename_session_data *data; + + *ptr = data = xmalloc(sizeof *data); + buffer_read(b, data, sizeof *data); + data->newname = cmd_recv_string(b); +} + +void +cmd_rename_session_free(void *ptr) +{ + struct cmd_rename_session_data *data = ptr; + + if (data->newname != NULL) + xfree(data->newname); + xfree(data); +} diff --git a/cmd-rename-window.c b/cmd-rename-window.c index 3d46bbc2..3691f68f 100644 --- a/cmd-rename-window.c +++ b/cmd-rename-window.c @@ -1,4 +1,4 @@ -/* $Id: cmd-rename-window.c,v 1.10 2007-10-30 10:59:43 nicm Exp $ */ +/* $Id: cmd-rename-window.c,v 1.11 2007-11-09 11:02:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -39,7 +39,7 @@ struct cmd_rename_window_data { }; const struct cmd_entry cmd_rename_window_entry = { - "rename-window", "renamew", "[-i index] new name", + "rename-window", "renamew", "[-i index] new-name", 0, cmd_rename_window_parse, cmd_rename_window_exec, diff --git a/cmd.c b/cmd.c index b7a54838..d0f6ab61 100644 --- a/cmd.c +++ b/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.24 2007-10-30 11:10:33 nicm Exp $ */ +/* $Id: cmd.c,v 1.25 2007-11-09 11:02:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -40,6 +40,7 @@ const struct cmd_entry *cmd_table[] = { &cmd_next_window_entry, &cmd_previous_window_entry, &cmd_refresh_session_entry, + &cmd_rename_session_entry, &cmd_rename_window_entry, &cmd_select_window_entry, &cmd_send_prefix_entry, diff --git a/tmux.h b/tmux.h index b59e29f7..47cc66a3 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.76 2007-10-31 14:26:26 nicm Exp $ */ +/* $Id: tmux.h,v 1.77 2007-11-09 11:02:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -583,6 +583,7 @@ extern const struct cmd_entry cmd_new_window_entry; extern const struct cmd_entry cmd_next_window_entry; extern const struct cmd_entry cmd_previous_window_entry; extern const struct cmd_entry cmd_refresh_session_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_select_window_entry; extern const struct cmd_entry cmd_send_prefix_entry;