summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-03 05:47:09 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-03 05:47:09 +0000
commit3e6b1459232e1ae4fd3bb55e95122cef369ae86b (patch)
treede87b51ba500e7aa7d1a4124a0fac8f6e7c4f52c
parentf91e7bfd381826eb88edacc7b5766c262a71b033 (diff)
Allow fnmatch(3) on -s, and select newest session if multiple.
-rw-r--r--CHANGES4
-rw-r--r--cmd.c33
2 files changed, 24 insertions, 13 deletions
diff --git a/CHANGES b/CHANGES
index 11a74aa2..621f9e45 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
03 June 2008
+* -s to specify session name now supports fnmatch(3) wildcards; if multiple
+ sessions are found, or if no -s is specified, the most newly created is used.
* If no command is specified, assume new-session. As a byproduct, clean up
command default values into seperate init functions.
* kill-server command.
@@ -374,4 +376,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.100 2008-06-03 05:35:50 nicm Exp $
+$Id: CHANGES,v 1.101 2008-06-03 05:47:09 nicm Exp $
diff --git a/cmd.c b/cmd.c
index cfae414e..3b179b85 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.37 2008-06-03 05:10:38 nicm Exp $ */
+/* $Id: cmd.c,v 1.38 2008-06-03 05:47:09 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -18,6 +18,7 @@
#include <sys/types.h>
+#include <fnmatch.h>
#include <getopt.h>
#include <string.h>
#include <unistd.h>
@@ -238,13 +239,24 @@ cmd_recv_string(struct buffer *b)
struct session *
cmd_find_session(struct cmd_ctx *ctx, const char *arg)
{
- struct session *s;
+ struct session *s, *sp;
struct msg_command_data *data = ctx->msgdata;
- u_int i, n;
+ u_int i;
+ time_t tim;
if (arg != NULL) {
- if ((s = session_find(arg)) == NULL) {
- ctx->error(ctx, "session not found: %s", arg);
+ s = NULL;
+ tim = 0;
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ sp = ARRAY_ITEM(&sessions, i);
+ if (sp != NULL &&
+ fnmatch(arg, sp->name, 0) == 0 && sp->tim > tim) {
+ s = sp;
+ tim = s->tim;
+ }
+ }
+ if (s == NULL) {
+ ctx->error(ctx, "no sessions matching: %s", arg);
return (NULL);
}
return (s);
@@ -270,21 +282,18 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg)
}
s = NULL;
- n = 0;
+ tim = 0;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
- if (ARRAY_ITEM(&sessions, i) != NULL) {
+ sp = ARRAY_ITEM(&sessions, i);
+ if (sp != NULL && sp->tim > tim) {
s = ARRAY_ITEM(&sessions, i);
- n++;
+ tim = s->tim;
}
}
if (s == NULL) {
ctx->error(ctx, "no sessions found");
return (NULL);
}
- if (n != 1) {
- ctx->error(ctx, "multiple sessions and session not specified");
- return (NULL);
- }
return (s);
}