summaryrefslogtreecommitdiffstats
path: root/op.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 14:08:16 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 14:08:16 +0000
commit65eeb7e421718e248790d858792fd820aabbdbe6 (patch)
treea145930e554bfb8a0609d588a8a95f740622f8de /op.c
parentfb39b22a2e7b7c12c56b26abc8ca18f38c2d7bda (diff)
Restore -n, now after the command.
Diffstat (limited to 'op.c')
-rw-r--r--op.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/op.c b/op.c
index 393ca69f..f5fa1485 100644
--- a/op.c
+++ b/op.c
@@ -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>
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <string.h>
+#include <unistd.h>
#include "tmux.h"
@@ -27,14 +28,32 @@ op_new(char *path, int argc, unused char **argv)
{
struct new_data data;
struct client_ctx cctx;
+ char name[MAXNAMELEN];
+ int opt;
- if (argc != 0) /* XXX -n */
- return (usage("new"));
+ optind = 1;
+ 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)
return (1);
- strlcpy(data.name, "XXX"/*XXX*/, sizeof data.name);
+ strlcpy(data.name, name, sizeof data.name);
data.sx = cctx.ws.ws_col;
data.sy = cctx.ws.ws_row;
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 client_ctx cctx;
+ char name[MAXNAMELEN];
+ int opt;
- if (argc != 0) /* XXX -n */
- return (usage("attach"));
+ optind = 1;
+ 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)
return (1);
- strlcpy(data.name, "XXX"/*XXX*/, sizeof data.name);
+ strlcpy(data.name, name, sizeof data.name);
data.sx = cctx.ws.ws_col;
data.sy = cctx.ws.ws_row;
client_write_server(&cctx, MSG_ATTACH, &data, sizeof data);