New session selection rules:

- find by name if given
	- otherwise try current index from $TMUX
	- otherwise if only one session, use it
	- otherwise error
This commit is contained in:
Nicholas Marriott
2007-09-27 09:52:03 +00:00
parent 3fa8f16364
commit 22990a6595
7 changed files with 131 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: client.c,v 1.5 2007-09-26 19:09:30 nicm Exp $ */
/* $Id: client.c,v 1.6 2007-09-27 09:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -196,6 +196,36 @@ local_dead:
fatalx("local socket dead");
}
void
client_fill_sessid(struct sessid *sid, char name[MAXNAMELEN])
{
char *env, *ptr, buf[256];
const char *errstr;
long long ll;
strlcpy(sid->name, name, sizeof sid->name);
sid->pid = -1;
if ((env = getenv("TMUX")) == NULL)
return;
if ((ptr = strchr(env, ',')) == NULL)
return;
if ((size_t) (ptr - env) > sizeof buf)
return;
memcpy(buf, env, ptr - env);
buf[ptr - env] = '\0';
ll = strtonum(ptr + 1, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return;
sid->idx = ll;
ll = strtonum(buf, 0, LLONG_MAX, &errstr);
if (errstr != NULL)
return;
sid->pid = ll;
}
void
client_write_server(
struct client_ctx *cctx, enum hdrtype type, void *buf, size_t len)