From 22990a6595fdff840010aa6df9a60ada61331b5e Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 27 Sep 2007 09:52:03 +0000 Subject: New session selection rules: - find by name if given - otherwise try current index from $TMUX - otherwise if only one session, use it - otherwise error --- client.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'client.c') diff --git a/client.c b/client.c index 3593cc58..fec1b81c 100644 --- a/client.c +++ b/client.c @@ -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 @@ -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) -- cgit