mirror of
https://github.com/tmux/tmux.git
synced 2025-01-14 20:58:53 +00:00
Sync OpenBSD patchset 360:
If no target client is specified to commands which accept one, try to guess the current client, in a similar manner to how sessions already work: if the current session can be established and has only one client, use that; otherwise use the most recently created client.
This commit is contained in:
parent
d8c0634524
commit
eb7f8b6d33
53
cmd.c
53
cmd.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd.c,v 1.118 2009-09-25 17:51:39 tcunha Exp $ */
|
/* $Id: cmd.c,v 1.119 2009-10-06 14:00:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -109,6 +109,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct session *cmd_newest_session(struct sessions *);
|
struct session *cmd_newest_session(struct sessions *);
|
||||||
|
struct client *cmd_newest_client(void);
|
||||||
struct client *cmd_lookup_client(const char *);
|
struct client *cmd_lookup_client(const char *);
|
||||||
struct session *cmd_lookup_session(const char *, int *);
|
struct session *cmd_lookup_session(const char *, int *);
|
||||||
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
|
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
|
||||||
@ -368,17 +369,63 @@ cmd_newest_session(struct sessions *ss)
|
|||||||
return (snewest);
|
return (snewest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Find the newest client. */
|
||||||
|
struct client *
|
||||||
|
cmd_newest_client(void)
|
||||||
|
{
|
||||||
|
struct client *c, *cnewest;
|
||||||
|
struct timeval *tv = NULL;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
cnewest = NULL;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
if ((c = ARRAY_ITEM(&clients, i)) == NULL)
|
||||||
|
continue;
|
||||||
|
if (c->session == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (tv == NULL || timercmp(&c->tv, tv, >)) {
|
||||||
|
cnewest = c;
|
||||||
|
tv = &c->tv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (cnewest);
|
||||||
|
}
|
||||||
|
|
||||||
/* Find the target client or report an error and return NULL. */
|
/* Find the target client or report an error and return NULL. */
|
||||||
struct client *
|
struct client *
|
||||||
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
|
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
|
||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
|
struct session *s;
|
||||||
char *tmparg;
|
char *tmparg;
|
||||||
size_t arglen;
|
size_t arglen;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
/* A NULL argument means the current client. */
|
/* A NULL argument means the current client. */
|
||||||
if (arg == NULL)
|
if (arg == NULL) {
|
||||||
return (ctx->curclient);
|
if (ctx->curclient != NULL)
|
||||||
|
return (ctx->curclient);
|
||||||
|
/*
|
||||||
|
* No current client set. Find the current session and see if
|
||||||
|
* it has only has one client.
|
||||||
|
*/
|
||||||
|
s = cmd_current_session(ctx);
|
||||||
|
if (s != NULL) {
|
||||||
|
c = NULL;
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||||
|
if (ARRAY_ITEM(&clients, i)->session == s) {
|
||||||
|
if (c != NULL)
|
||||||
|
break;
|
||||||
|
c = ARRAY_ITEM(&clients, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == ARRAY_LENGTH(&clients) && c != NULL)
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
|
return (cmd_newest_client());
|
||||||
|
}
|
||||||
tmparg = xstrdup(arg);
|
tmparg = xstrdup(arg);
|
||||||
|
|
||||||
/* Trim a single trailing colon if any. */
|
/* Trim a single trailing colon if any. */
|
||||||
|
5
server.c
5
server.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: server.c,v 1.194 2009-09-25 17:47:42 tcunha Exp $ */
|
/* $Id: server.c,v 1.195 2009-10-06 14:00:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -89,6 +89,9 @@ server_create_client(int fd)
|
|||||||
c = xcalloc(1, sizeof *c);
|
c = xcalloc(1, sizeof *c);
|
||||||
c->references = 0;
|
c->references = 0;
|
||||||
imsg_init(&c->ibuf, fd);
|
imsg_init(&c->ibuf, fd);
|
||||||
|
|
||||||
|
if (gettimeofday(&c->tv, NULL) != 0)
|
||||||
|
fatal("gettimeofday failed");
|
||||||
|
|
||||||
ARRAY_INIT(&c->prompt_hdata);
|
ARRAY_INIT(&c->prompt_hdata);
|
||||||
|
|
||||||
|
3
tmux.h
3
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.456 2009-09-25 17:51:39 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.457 2009-10-06 14:00:50 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -920,6 +920,7 @@ struct tty_ctx {
|
|||||||
/* Client connection. */
|
/* Client connection. */
|
||||||
struct client {
|
struct client {
|
||||||
struct imsgbuf ibuf;
|
struct imsgbuf ibuf;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
struct environ environ;
|
struct environ environ;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user