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 @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -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); }