Restore -n, now after the command.

This commit is contained in:
Nicholas Marriott 2007-09-26 14:08:16 +00:00
parent fb39b22a2e
commit 65eeb7e421
3 changed files with 51 additions and 18 deletions

9
NOTES
View File

@ -12,7 +12,6 @@ Commands: d detach
p previous window p previous window
l last (next to last selected) window l last (next to last selected) window
r refresh screen r refresh screen
t set window name
w list current windows w list current windows
0-9 select window 0-9 select window
@ -21,7 +20,7 @@ There is one default server process per user which puts its socket in
invocations will connect to the same server. The server holds multiple invocations will connect to the same server. The server holds multiple
sessions. sessions.
Syntax is: tmux [-v] [-n name] [-s path] command Syntax is: tmux [-v] [-s path] command [flags]
The command is either list, new or attach. Create a new session with: The command is either list, new or attach. Create a new session with:
@ -29,11 +28,11 @@ The command is either list, new or attach. Create a new session with:
Optionally giving it a name with: Optionally giving it a name with:
tmux -n <session name> new tmux new -n <session name>
Attach to a previous session with: Attach to a previous session with:
tmux -n <session name> attach tmux attach -n <session name>
A name must (currently) be specified when attaching. This may change. A name must (currently) be specified when attaching. This may change.
@ -43,7 +42,7 @@ List all sessions with:
Or the windows of a single session with: Or the windows of a single session with:
tmux -n <session name> list tmux list -n <session name>
Sessions are destroyed when no windows remain attached to them. Sessions are destroyed when no windows remain attached to them.

51
op.c
View File

@ -1,4 +1,4 @@
/* $Id: op.c,v 1.1 2007-09-26 13:43:15 nicm Exp $ */ /* $Id: op.c,v 1.2 2007-09-26 14:08:16 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -19,6 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "tmux.h" #include "tmux.h"
@ -27,14 +28,32 @@ op_new(char *path, int argc, unused char **argv)
{ {
struct new_data data; struct new_data data;
struct client_ctx cctx; struct client_ctx cctx;
char name[MAXNAMELEN];
int opt;
if (argc != 0) /* XXX -n */ optind = 1;
return (usage("new")); while ((opt = getopt(argc, argv, "n:?")) != EOF) {
switch (opt) {
case 'n':
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
log_warnx("%s: session name too long", optarg);
return (1);
}
break;
case '?':
default:
return (usage("new [-n session]"));
}
}
argc -= optind;
argv += optind;
if (argc != 0)
return (usage("new [-n session]"));
if (client_init(path, &cctx, 1) != 0) if (client_init(path, &cctx, 1) != 0)
return (1); return (1);
strlcpy(data.name, "XXX"/*XXX*/, sizeof data.name); strlcpy(data.name, name, sizeof data.name);
data.sx = cctx.ws.ws_col; data.sx = cctx.ws.ws_col;
data.sy = cctx.ws.ws_row; data.sy = cctx.ws.ws_row;
client_write_server(&cctx, MSG_NEW, &data, sizeof data); client_write_server(&cctx, MSG_NEW, &data, sizeof data);
@ -47,14 +66,32 @@ op_attach(char *path, int argc, unused char **argv)
{ {
struct attach_data data; struct attach_data data;
struct client_ctx cctx; struct client_ctx cctx;
char name[MAXNAMELEN];
int opt;
if (argc != 0) /* XXX -n */ optind = 1;
return (usage("attach")); while ((opt = getopt(argc, argv, "n:?")) != EOF) {
switch (opt) {
case 'n':
if (strlcpy(name, optarg, sizeof name) >= sizeof name) {
log_warnx("%s: session name too long", optarg);
return (1);
}
break;
case '?':
default:
return (usage("attach [-n session]"));
}
}
argc -= optind;
argv += optind;
if (argc != 0)
return (usage("attach [-n session]"));
if (client_init(path, &cctx, 1) != 0) if (client_init(path, &cctx, 1) != 0)
return (1); return (1);
strlcpy(data.name, "XXX"/*XXX*/, sizeof data.name); strlcpy(data.name, name, sizeof data.name);
data.sx = cctx.ws.ws_col; data.sx = cctx.ws.ws_col;
data.sy = cctx.ws.ws_row; data.sy = cctx.ws.ws_row;
client_write_server(&cctx, MSG_ATTACH, &data, sizeof data); client_write_server(&cctx, MSG_ATTACH, &data, sizeof data);

9
tmux.c
View File

@ -1,4 +1,4 @@
/* $Id: tmux.c,v 1.9 2007-09-26 13:43:15 nicm Exp $ */ /* $Id: tmux.c,v 1.10 2007-09-26 14:08:16 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -53,7 +53,7 @@ int
usage(const char *s) usage(const char *s)
{ {
if (s == NULL) if (s == NULL)
s = "command ..."; s = "command [flags]";
fprintf(stderr, "usage: %s [-v] [-s path] %s\n", __progname, s); fprintf(stderr, "usage: %s [-v] [-s path] %s\n", __progname, s);
return (1); return (1);
} }
@ -182,11 +182,8 @@ main(int argc, char **argv)
for (i = 0; i < NOP; i++) { for (i = 0; i < NOP; i++) {
op = op_table + i; op = op_table + i;
if (strncmp(argv[0], op->cmd, strlen(op->cmd)) == 0) { if (strncmp(argv[0], op->cmd, strlen(op->cmd)) == 0)
argc--;
argv++;
exit(op->fn(path, argc, argv)); exit(op->fn(path, argc, argv));
}
} }
exit(usage(NULL)); exit(usage(NULL));