mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-26 10:03:08 +01:00
Adjust $TMUX environ var to include session index, and don't compact session list on release. Also fix some argument types.
This commit is contained in:
parent
187648e8d1
commit
3fa8f16364
14
TODO
14
TODO
@ -13,10 +13,10 @@
|
||||
- scrollback
|
||||
- server doesn't handle SIGTERM anymore...
|
||||
- sleep(1) to wait for server frankly sucks
|
||||
- two-way communication (rename) sucks. lose it and use a command line option
|
||||
for everythin
|
||||
- toolbar, copy/paste
|
||||
- cleanup/redesign IPC
|
||||
- the whole input/screen/local thing sucks a bit, reorganise/redesign it
|
||||
- line mode/char-at-a-time mode a la telnet?
|
||||
- some of the uses of buffers really sucks. buffer_reverse_add/remove,
|
||||
and buffer_insert_range/delete_range are abominations. this should be
|
||||
rethought
|
||||
@ -32,3 +32,13 @@
|
||||
- inside tmux, check $TMUX (pid:session or something)
|
||||
- otherwise if 1 session, use it
|
||||
- otherwise bail with error
|
||||
- keys to add:
|
||||
i : show window info (show name, title, size, tty, ...)
|
||||
- commands to add:
|
||||
rename window/sessions
|
||||
swap windows
|
||||
link/copy windows
|
||||
detach session
|
||||
unlink window (... what about windows not linked to any session???)
|
||||
close window
|
||||
kill session
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: client-cmd.c,v 1.3 2007-09-26 18:50:49 nicm Exp $ */
|
||||
/* $Id: client-cmd.c,v 1.4 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -58,7 +58,7 @@ struct cmd client_cmd_table[] = {
|
||||
{ 'L', client_cmd_fn_msg, MSG_LAST },
|
||||
{ 'l', client_cmd_fn_msg, MSG_LAST },
|
||||
{ 'W', client_cmd_fn_msg, MSG_WINDOWLIST },
|
||||
{ 'w', client_cmd_fn_msg, MSG_WINDOWLIST }
|
||||
{ 'w', client_cmd_fn_msg, MSG_WINDOWLIST },
|
||||
};
|
||||
#define NCLIENTCMD (sizeof client_cmd_table / sizeof client_cmd_table[0])
|
||||
|
||||
|
21
server-fn.c
21
server-fn.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server-fn.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
|
||||
/* $Id: server-fn.c,v 1.3 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -24,11 +24,13 @@
|
||||
|
||||
/* Write command to a client. */
|
||||
void
|
||||
server_write_client(struct client *c, u_int cmd, void *buf, size_t len)
|
||||
server_write_client(struct client *c, enum hdrtype type, void *buf, size_t len)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = cmd;
|
||||
log_debug("writing %d to client %d", type, c->fd);
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len;
|
||||
|
||||
buffer_write(c->out, &hdr, sizeof hdr);
|
||||
@ -39,11 +41,13 @@ server_write_client(struct client *c, u_int cmd, void *buf, size_t len)
|
||||
/* Write command to a client with two buffers. */
|
||||
void
|
||||
server_write_client2(struct client *c,
|
||||
u_int cmd, void *buf1, size_t len1, void *buf2, size_t len2)
|
||||
enum hdrtype type, void *buf1, size_t len1, void *buf2, size_t len2)
|
||||
{
|
||||
struct hdr hdr;
|
||||
|
||||
hdr.type = cmd;
|
||||
log_debug("writing %d to client %d", type, c->fd);
|
||||
|
||||
hdr.type = type;
|
||||
hdr.size = len1 + len2;
|
||||
|
||||
buffer_write(c->out, &hdr, sizeof hdr);
|
||||
@ -55,19 +59,22 @@ server_write_client2(struct client *c,
|
||||
|
||||
/* Write command to all clients attached to a specific window. */
|
||||
void
|
||||
server_write_clients(struct window *w, u_int cmd, void *buf, size_t len)
|
||||
server_write_clients(
|
||||
struct window *w, enum hdrtype type, void *buf, size_t len)
|
||||
{
|
||||
struct client *c;
|
||||
struct hdr hdr;
|
||||
u_int i;
|
||||
|
||||
hdr.type = cmd;
|
||||
hdr.type = type;
|
||||
hdr.size = len;
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
|
||||
c = ARRAY_ITEM(&clients, i);
|
||||
if (c != NULL && c->session != NULL) {
|
||||
if (c->session->window == w) {
|
||||
log_debug(
|
||||
"writing %d to clients: %d", type, c->fd);
|
||||
buffer_write(c->out, &hdr, sizeof hdr);
|
||||
if (buf != NULL)
|
||||
buffer_write(c->out, buf, len);
|
||||
|
4
server.c
4
server.c
@ -1,4 +1,4 @@
|
||||
/* $Id: server.c,v 1.14 2007-09-26 18:09:23 nicm Exp $ */
|
||||
/* $Id: server.c,v 1.15 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -321,6 +321,8 @@ server_lost_window(struct window *w)
|
||||
u_int i, j;
|
||||
int destroyed;
|
||||
|
||||
log_debug("lost window %d", w->fd);
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
s = ARRAY_ITEM(&sessions, i);
|
||||
if (s == NULL)
|
||||
|
29
session.c
29
session.c
@ -1,4 +1,4 @@
|
||||
/* $Id: session.c,v 1.15 2007-09-21 20:45:05 nicm Exp $ */
|
||||
/* $Id: session.c,v 1.16 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -20,6 +20,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@ -54,11 +55,6 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
|
||||
s->window = s->last = NULL;
|
||||
ARRAY_INIT(&s->windows);
|
||||
|
||||
if (session_new(s, cmd, sx, sy) != 0) {
|
||||
xfree(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||
if (ARRAY_ITEM(&sessions, i) == NULL) {
|
||||
ARRAY_SET(&sessions, i, s);
|
||||
@ -73,6 +69,11 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
|
||||
else
|
||||
xsnprintf(s->name, sizeof s->name, "%u", i);
|
||||
|
||||
if (session_new(s, cmd, sx, sy) != 0) {
|
||||
session_destroy(s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
return (s);
|
||||
}
|
||||
|
||||
@ -84,8 +85,10 @@ session_destroy(struct session *s)
|
||||
|
||||
if (session_index(s, &i) != 0)
|
||||
fatalx("session not found");
|
||||
ARRAY_REMOVE(&sessions, i);
|
||||
|
||||
ARRAY_SET(&sessions, i, NULL);
|
||||
while (!ARRAY_EMPTY(&sessions) && ARRAY_LAST(&sessions) == NULL)
|
||||
ARRAY_TRUNC(&sessions, 1);
|
||||
|
||||
while (!ARRAY_EMPTY(&s->windows))
|
||||
window_remove(&s->windows, ARRAY_FIRST(&s->windows));
|
||||
|
||||
@ -108,8 +111,16 @@ int
|
||||
session_new(struct session *s, const char *cmd, u_int sx, u_int sy)
|
||||
{
|
||||
struct window *w;
|
||||
const char *environ[] = { NULL, "TERM=screen", NULL };
|
||||
char blk[256];
|
||||
u_int i;
|
||||
|
||||
if ((w = window_create(cmd, sx, sy)) == NULL)
|
||||
if (session_index(s, &i) != 0)
|
||||
fatalx("session not found");
|
||||
xsnprintf(blk, sizeof blk, "TMUX=%ld,%u", (long) getpid(), i);
|
||||
environ[0] = blk;
|
||||
|
||||
if ((w = window_create(cmd, environ, sx, sy)) == NULL)
|
||||
return (-1);
|
||||
session_attach(s, w);
|
||||
|
||||
|
8
tmux.c
8
tmux.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.c,v 1.13 2007-09-26 19:38:42 nicm Exp $ */
|
||||
/* $Id: tmux.c,v 1.14 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -45,8 +45,10 @@ struct op {
|
||||
};
|
||||
struct op op_table[] = {
|
||||
{ "attach", NULL, op_attach },
|
||||
{ "list-sessions", "ls", op_list },
|
||||
{ "new-session", "new", op_new },
|
||||
{ "list-sessions", "ls", op_list/*_sessions*/ },
|
||||
{ "new-session", "new", op_new/*_session*/ },
|
||||
// { "rename-window", "rw", op_rename_window },
|
||||
// { "rename-session", "rs", op_rename_session },
|
||||
};
|
||||
#define NOP (sizeof op_table / sizeof op_table[0])
|
||||
|
||||
|
10
tmux.h
10
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.15 2007-09-26 18:50:49 nicm Exp $ */
|
||||
/* $Id: tmux.h,v 1.16 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -466,10 +466,10 @@ int server_msg_dispatch(struct client *);
|
||||
|
||||
/* server-fn.c */
|
||||
void server_write_message(struct client *, const char *, ...);
|
||||
void server_write_client(struct client *, u_int, void *, size_t);
|
||||
void server_write_client(struct client *, enum hdrtype, void *, size_t);
|
||||
void server_write_client2(
|
||||
struct client *, u_int, void *, size_t, void *, size_t);
|
||||
void server_write_clients(struct window *, u_int, void *, size_t);
|
||||
struct client *, enum hdrtype, void *, size_t, void *, size_t);
|
||||
void server_write_clients(struct window *, enum hdrtype, void *, size_t);
|
||||
void server_window_changed(struct client *);
|
||||
void server_draw_client(struct client *, u_int, u_int);
|
||||
|
||||
@ -499,7 +499,7 @@ void local_output(struct buffer *, size_t);
|
||||
|
||||
/* window.c */
|
||||
extern struct windows windows;
|
||||
struct window *window_create(const char *, u_int, u_int);
|
||||
struct window *window_create(const char *, const char **, u_int, u_int);
|
||||
int window_index(struct windows *, struct window *, u_int *);
|
||||
void window_add(struct windows *, struct window *);
|
||||
void window_remove(struct windows *, struct window *);
|
||||
|
41
window.c
41
window.c
@ -1,4 +1,4 @@
|
||||
/* $Id: window.c,v 1.10 2007-09-21 20:45:06 nicm Exp $ */
|
||||
/* $Id: window.c,v 1.11 2007-09-27 09:15:58 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -52,14 +52,14 @@ struct windows windows;
|
||||
|
||||
/* Create a new window. */
|
||||
struct window *
|
||||
window_create(const char *cmd, u_int sx, u_int sy)
|
||||
window_create(const char *cmd, const char **environ, u_int sx, u_int sy)
|
||||
{
|
||||
struct window *w;
|
||||
struct winsize ws;
|
||||
struct termios tio;
|
||||
struct sigaction act;
|
||||
int fd, mode;
|
||||
char pid[16], *ptr, *name;
|
||||
char *ptr, *name;
|
||||
const char **entry;
|
||||
|
||||
memset(&ws, 0, sizeof ws);
|
||||
ws.ws_col = sx;
|
||||
@ -73,40 +73,17 @@ window_create(const char *cmd, u_int sx, u_int sy)
|
||||
memcpy(&tio.c_cc, ttydefchars, sizeof tio.c_cc);
|
||||
cfsetspeed(&tio, TTYDEF_SPEED);
|
||||
|
||||
xsnprintf(pid, sizeof pid, "%ld", (long) getpid());
|
||||
switch (forkpty(&fd, NULL, &tio, &ws)) {
|
||||
case -1:
|
||||
return (NULL);
|
||||
case 0:
|
||||
if (setenv("TMUX", pid, 1) != 0)
|
||||
fatal("setenv failed");
|
||||
if (setenv("TERM", "screen", 1) != 0)
|
||||
fatal("setenv failed");
|
||||
for (entry = environ; *entry != NULL; entry++) {
|
||||
if (putenv(*entry) != 0)
|
||||
fatal("putenv failed");
|
||||
}
|
||||
sigreset();
|
||||
log_close();
|
||||
|
||||
memset(&act, 0, sizeof act);
|
||||
sigemptyset(&act.sa_mask);
|
||||
|
||||
act.sa_handler = SIG_DFL;
|
||||
if (sigaction(SIGPIPE, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGUSR1, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGUSR2, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGINT, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGTSTP, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGQUIT, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGWINCH, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGTERM, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
if (sigaction(SIGCHLD, &act, NULL) != 0)
|
||||
fatal("sigaction failed");
|
||||
|
||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
||||
fatal("execl failed");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user