aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--TODO3
-rw-r--r--client-cmd.c4
-rw-r--r--op.c54
-rw-r--r--server-msg.c36
-rw-r--r--tmux.c6
-rw-r--r--tmux.h9
7 files changed, 100 insertions, 17 deletions
diff --git a/CHANGES b/CHANGES
index f7b9091b..a07d365d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+28 September 2007
+ * (mxey) Added window remaming, like "tmux rename [-s session] [-i index] name"
+
27 September 2007
* Split "tmux list" into "tmux list-sessions" (ls) and "list-windows" (lsw).
@@ -55,5 +58,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.11 2007-09-27 10:14:10 nicm Exp $
+$Id: CHANGES,v 1.12 2007-09-28 21:41:51 mxey Exp $
diff --git a/TODO b/TODO
index 90a888b2..7cffe15c 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
- key remapping
- decide if TIOCPKT is necessary and either handle it or remove the code
- it would be nice if there wasn't so much copying buffers about, audit uses
-- window names
- status bar
- useful env vars like WINDOW
- lots of scripting love: add, remove, move around windows, status bar
@@ -25,7 +24,7 @@
i : show window info (show name, title, size, tty, ...)
meta-meta : pass through meta (will need this...)
- commands to add:
- rename window/sessions
+ rename sessions
swap windows
link/copy windows
detach session
diff --git a/client-cmd.c b/client-cmd.c
index 94dccd3f..6fa2370c 100644
--- a/client-cmd.c
+++ b/client-cmd.c
@@ -1,4 +1,4 @@
-/* $Id: client-cmd.c,v 1.4 2007-09-27 09:15:58 nicm Exp $ */
+/* $Id: client-cmd.c,v 1.5 2007-09-28 21:41:52 mxey Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -53,8 +53,6 @@ struct cmd client_cmd_table[] = {
{ 'p', client_cmd_fn_msg, MSG_PREVIOUS },
{ 'R', client_cmd_fn_msg, MSG_REFRESH },
{ 'r', client_cmd_fn_msg, MSG_REFRESH },
- { 'T', client_cmd_fn_msg, MSG_RENAME },
- { 't', client_cmd_fn_msg, MSG_RENAME },
{ 'L', client_cmd_fn_msg, MSG_LAST },
{ 'l', client_cmd_fn_msg, MSG_LAST },
{ 'W', client_cmd_fn_msg, MSG_WINDOWLIST },
diff --git a/op.c b/op.c
index 22377d80..3e6551f5 100644
--- a/op.c
+++ b/op.c
@@ -1,4 +1,4 @@
-/* $Id: op.c,v 1.6 2007-09-27 09:52:03 nicm Exp $ */
+/* $Id: op.c,v 1.7 2007-09-28 21:41:52 mxey Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,6 +18,7 @@
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -101,3 +102,54 @@ op_attach(char *path, int argc, char **argv)
return (client_main(&cctx));
}
+int
+op_rename(char *path, int argc, char **argv)
+{
+ struct rename_data data;
+ struct client_ctx cctx;
+ char sname[MAXNAMELEN];
+ int opt;
+ const char *errstr;
+
+ *sname = '\0';
+ data.idx = -1;
+ optind = 1;
+ while ((opt = getopt(argc, argv, "i:s:?")) != EOF) {
+ switch (opt) {
+ case 's':
+ if (strlcpy(sname, optarg, sizeof sname)
+ >= sizeof sname) {
+ log_warnx("%s: session name too long", optarg);
+ return (1);
+ }
+ break;
+ case 'i':
+ data.idx = strtonum(optarg, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ log_warnx("%s: window index %s", optarg,
+ errstr);
+ return (1);
+ break;
+ case '?':
+ default:
+ return (usage("rename [-s session] [-i index] name"));
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc != 1)
+ return (usage("rename [-s session] [-i index] name"));
+
+ if (client_init(path, &cctx, 1) != 0)
+ return (1);
+
+ client_fill_sessid(&data.sid, sname);
+ if ((strlcpy(data.newname, argv[0], sizeof data.newname)
+ >= sizeof data.newname)) {
+ log_warnx("%s: new window name too long", argv[0]);
+ return (1);
+ }
+ client_write_server(&cctx, MSG_RENAME, &data, sizeof data);
+
+ return (client_flush(&cctx));
+}
diff --git a/server-msg.c b/server-msg.c
index 8a680018..9ec5ecbb 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.6 2007-09-28 21:08:30 nicm Exp $ */
+/* $Id: server-msg.c,v 1.7 2007-09-28 21:41:52 mxey Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -385,12 +385,38 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
int
server_msg_fn_rename(struct hdr *hdr, struct client *c)
{
- if (c->session == NULL)
- return (0);
- if (hdr->size != 0)
+ struct rename_data data;
+ char *cause;
+ struct window *w;
+ struct session *s;
+
+
+ if (hdr->size != sizeof data)
fatalx("bad MSG_RENAME size");
- fatalx("not implemented");
+ buffer_read(c->in, &data, hdr->size);
+
+ data.newname[sizeof data.newname] = '\0';
+
+ if ((s = server_find_sessid(&data.sid, &cause)) == NULL) {
+ /* XXX: Send message to client */
+ return (0);
+ }
+
+ if (data.idx == -1)
+ w = s->window;
+ else
+ w = window_at(&s->windows, data.idx);
+
+ if (w == NULL) {
+ /* XXX: Send message to client */
+ return (0);
+ }
+
+ strlcpy(w->name, data.newname, sizeof w->name);
+
+ return (0);
+
}
/* Last window message from client */
diff --git a/tmux.c b/tmux.c
index a68d5456..2456b73b 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.16 2007-09-27 20:54:43 nicm Exp $ */
+/* $Id: tmux.c,v 1.17 2007-09-28 21:41:52 mxey Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -48,9 +48,7 @@ struct op op_table[] = {
{ "list-sessions", "ls", op_list_sessions },
{ "list-windows", "lsw", op_list_windows },
{ "new-session", "new", op_new/*_session*/ },
-// { "new-window", "neww", op_new_window },
-// { "rename-window", "rw", op_rename_window },
-// { "rename-session", "rs", op_rename_session },
+ { "rename-window", NULL, op_rename },
};
#define NOP (sizeof op_table / sizeof op_table[0])
diff --git a/tmux.h b/tmux.h
index 901c2cdd..9f01ae5c 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.19 2007-09-28 19:04:21 nicm Exp $ */
+/* $Id: tmux.h,v 1.20 2007-09-28 21:41:52 mxey Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -341,6 +341,12 @@ struct refresh_data {
u_int py_lower;
};
+struct rename_data {
+ int idx;
+ struct sessid sid;
+ char newname[MAXNAMELEN];
+};
+
/* Attributes. */
#define ATTR_BRIGHT 0x1
#define ATTR_DIM 0x2
@@ -448,6 +454,7 @@ void sigreset(void);
/* op.c */
int op_new(char *, int, char **);
int op_attach(char *, int, char **);
+int op_rename(char *, int, char **);
/* op-list.c */
int op_list_sessions(char *, int, char **);