mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Allow fnmatch(3) on -s, and select newest session if multiple.
This commit is contained in:
parent
f91e7bfd38
commit
3e6b145923
4
CHANGES
4
CHANGES
@ -1,5 +1,7 @@
|
|||||||
03 June 2008
|
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
|
* If no command is specified, assume new-session. As a byproduct, clean up
|
||||||
command default values into seperate init functions.
|
command default values into seperate init functions.
|
||||||
* kill-server command.
|
* kill-server command.
|
||||||
@ -374,4 +376,4 @@
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
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 $
|
||||||
|
33
cmd.c
33
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>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <fnmatch.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -238,13 +239,24 @@ cmd_recv_string(struct buffer *b)
|
|||||||
struct session *
|
struct session *
|
||||||
cmd_find_session(struct cmd_ctx *ctx, const char *arg)
|
cmd_find_session(struct cmd_ctx *ctx, const char *arg)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s, *sp;
|
||||||
struct msg_command_data *data = ctx->msgdata;
|
struct msg_command_data *data = ctx->msgdata;
|
||||||
u_int i, n;
|
u_int i;
|
||||||
|
time_t tim;
|
||||||
|
|
||||||
if (arg != NULL) {
|
if (arg != NULL) {
|
||||||
if ((s = session_find(arg)) == NULL) {
|
s = NULL;
|
||||||
ctx->error(ctx, "session not found: %s", arg);
|
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 (NULL);
|
||||||
}
|
}
|
||||||
return (s);
|
return (s);
|
||||||
@ -270,21 +282,18 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
s = NULL;
|
s = NULL;
|
||||||
n = 0;
|
tim = 0;
|
||||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
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);
|
s = ARRAY_ITEM(&sessions, i);
|
||||||
n++;
|
tim = s->tim;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
ctx->error(ctx, "no sessions found");
|
ctx->error(ctx, "no sessions found");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (n != 1) {
|
|
||||||
ctx->error(ctx, "multiple sessions and session not specified");
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user