summaryrefslogtreecommitdiffstats
authornicm <nicm>2008-06-02 21:08:36 (GMT)
committer nicm <nicm>2008-06-02 21:08:36 (GMT)
commitb5ae4fba0fdc5edb3e81be98b528243a745aff4a (patch) (side-by-side diff)
tree1172209f7c1de7634f34be5f9087fe2b7d1fd4cd
parent195f66e80d4be7f31587217ae28351e1ba53b995 (diff)
downloadtmux-old-b5ae4fba0fdc5edb3e81be98b528243a745aff4a.zip
tmux-old-b5ae4fba0fdc5edb3e81be98b528243a745aff4a.tar.gz
tmux-old-b5ae4fba0fdc5edb3e81be98b528243a745aff4a.tar.bz2
Last bits of basic configuration file. By default in ~/.tmux.conf or specified with -f. Just a list of tmux commands executed when the server is started and before and any session/window is created.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--CHANGES38
-rw-r--r--Makefile5
-rw-r--r--TODO1
-rw-r--r--cfg.c23
-rw-r--r--client.c8
-rw-r--r--cmd-attach-session.c2
-rw-r--r--cmd-bind-key.c2
-rw-r--r--cmd-generic.c4
-rw-r--r--cmd-has-session.c21
-rw-r--r--cmd-kill-window.c2
-rw-r--r--cmd-link-window.c2
-rw-r--r--cmd-new-session.c46
-rw-r--r--cmd-new-window.c2
-rw-r--r--cmd-rename-session.c2
-rw-r--r--cmd-rename-window.c2
-rw-r--r--cmd-select-window.c2
-rw-r--r--cmd-send-keys.c2
-rw-r--r--cmd-set-option.c2
-rw-r--r--cmd-swap-window.c2
-rw-r--r--cmd-switch-client.c2
-rw-r--r--cmd-unbind-key.c2
-rw-r--r--cmd-unlink-window.c2
-rw-r--r--cmd.c3
-rw-r--r--server.c32
-rw-r--r--session.c4
-rw-r--r--tmux.c35
-rw-r--r--tmux.h4
27 files changed, 149 insertions, 103 deletions
diff --git a/CHANGES b/CHANGES
index 7976af5..6185202 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2,2 +2,40 @@
+* New command, start-server (alias "start"), to start the tmux server and do
+ nothing else. This is good if you have a configuration file which creates
+ windows or sessions (like me): in that case, starting the server the first
+ time tmux new is run is bad since it creates a new session and window (as
+ it is supposed to - starting the server is a side-effect).
+
+ Instead, I have a little script which does the equivalent of:
+
+ tmux has -s0 2>/dev/null || tmux start
+ tmux attach -d -s0
+
+ And I use it to start the server if necessary and attach to my primary
+ session.
+* Basic configuration file in ~/.tmux.conf or specified with -f. This is file
+ contains a set of tmux commands that are run the first time the server is
+ started. The configuration commands are executed before any others, so
+ if you have a configuration file that contains:
+
+ new -d
+ neww -s0
+
+ And you do the following without an existing server running:
+
+ tmux new
+
+ You will end up with two sessions, session 0 with two windows (created by
+ the configuration file) and your client attached to session 1 with one
+ window (created by the command-line command). I'm not completely happy with
+ this, it seems a little non-obvious, but I haven't yet decided what to do
+ about it.
+
+ There is no environment variable handling or other special stuff yet.
+
+ In the future, it might be nice to be able to have per-session configuration
+ settings, probably by having conditionals in the file (so you could, for
+ example, have commands to define a particular window layout that would only
+ be invoked if you called tmux new -smysession and mysession did not already
+ exist).
* BIG CHANGE: -s and -c to specify session name and client name are now passed
diff --git a/Makefile b/Makefile
index 6682b5e..6494a14 100644
--- a/Makefile
+++ b/Makefile
@@ -29,4 +29,5 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
- cmd-paste-buffer.c cmd-new-session.c window-scroll.c window-more.c \
- window-copy.c tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
+ cmd-paste-buffer.c cmd-new-session.c cmd-start-server.c \
+ window-scroll.c window-more.c window-copy.c \
+ tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
diff --git a/TODO b/TODO
index 4fcdc6f..627da0f 100644
--- a/TODO
+++ b/TODO
@@ -71,2 +71,3 @@
- different screen model? layers perhaps? hmm
+- cfg file improvements: * comments to EOL
diff --git a/cfg.c b/cfg.c
index 0c8dab2..1789325 100644
--- a/cfg.c
+++ b/cfg.c
@@ -75,3 +75,3 @@ load_cfg(const char *path, char **causep)
- line = 1;
+ line = 0;
while ((ch = getc(f)) != EOF) {
@@ -100,13 +100,14 @@ load_cfg(const char *path, char **causep)
case '\t':
- if (len == 0)
- break;
- buf[len] = '\0';
-
- argv = xrealloc(argv, argc + 1, sizeof (char *));
- argv[argc++] = buf;
+ if (len != 0) {
+ buf[len] = '\0';
- buf = NULL;
- len = 0;
+ argv = xrealloc(
+ argv, argc + 1, sizeof (char *));
+ argv[argc++] = buf;
+
+ buf = NULL;
+ len = 0;
+ }
- if (ch != '\n' && ch != EOF)
+ if ((ch != '\n' && ch != EOF) || argc == 0)
break;
@@ -125,3 +126,3 @@ load_cfg(const char *path, char **causep)
ctx.cmdclient = NULL;
- ctx.flags = CMD_KEY;
+ ctx.flags = 0;
diff --git a/client.c b/client.c
index 45692ab..9fc6bae 100644
--- a/client.c
+++ b/client.c
@@ -47,3 +47,5 @@ client_init(const char *path, struct client_ctx *cctx, int start_server)
struct buffer *b;
+ pid_t pid;
+ pid = 0;
retries = 0;
@@ -52,4 +54,4 @@ retry:
if (start_server && errno == ENOENT && retries < 10) {
- if (server_start(path) != 0)
- return (-1);
+ if (pid == 0)
+ pid = server_start(path);
usleep(10000);
@@ -114,3 +116,3 @@ fail:
log_warn("server not found");
- return (-1);
+ return (1);
}
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index 6f0d202..ceeb3f2 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -81,3 +81,3 @@ cmd_attach_session_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index bddc231..7a34736 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -84,3 +84,3 @@ cmd_bind_key_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-generic.c b/cmd-generic.c
index ecb0b36..6714ef6 100644
--- a/cmd-generic.c
+++ b/cmd-generic.c
@@ -59,3 +59,3 @@ cmd_clientonly_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
@@ -131,3 +131,3 @@ cmd_sessiononly_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-has-session.c b/cmd-has-session.c
index e4a178e..40be25f 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -26,5 +26,3 @@
/*
- * Cause client to exit with 0 if session exists, or 1 if it doesn't. This
- * is handled in the caller since this doesn't have flag CMD_NOSESSION, so
- * all that is necessary is to exit.
+ * Cause client to report an error and exit with 1 if session doesn't exist.
*/
@@ -35,9 +33,9 @@ const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
- "",
+ CMD_SESSIONONLY_USAGE,
0,
- NULL,
+ cmd_sessiononly_parse,
cmd_has_session_exec,
- NULL,
- NULL,
- NULL
+ cmd_sessiononly_send,
+ cmd_sessiononly_recv,
+ cmd_sessiononly_free
};
@@ -45,4 +43,9 @@ const struct cmd_entry cmd_has_session_entry = {
void
-cmd_has_session_exec(unused void *ptr, struct cmd_ctx *ctx)
+cmd_has_session_exec(void *ptr, struct cmd_ctx *ctx)
{
+ struct session *s;
+
+ if ((s = cmd_sessiononly_get(ptr, ctx)) == NULL)
+ return;
+
if (ctx->cmdclient != NULL)
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index 02ee076..bbdd912 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -87,3 +87,3 @@ cmd_kill_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-link-window.c b/cmd-link-window.c
index 946af70..48bf4c6 100644
--- a/cmd-link-window.c
+++ b/cmd-link-window.c
@@ -108,3 +108,3 @@ cmd_link_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-new-session.c b/cmd-new-session.c
index fa78e0c..c4b9329 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -91,3 +91,3 @@ cmd_new_session_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
@@ -103,4 +103,5 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
struct client *c = ctx->cmdclient;
+ struct session *s;
char *cmd, *cause;
- u_int sy;
+ u_int sx, sy;
@@ -112,5 +113,11 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
- if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) {
- ctx->error(ctx, "not a terminal");
- return;
+ if (!data->flag_detached) {
+ if (c == NULL) {
+ ctx->error(ctx, "no client to attach to");
+ return;
+ }
+ if (!(c->flags & CLIENT_TERMINAL)) {
+ ctx->error(ctx, "not a terminal");
+ return;
+ }
}
@@ -122,3 +129,12 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
- sy = c->sy;
+ cmd = data->cmd;
+ if (cmd == NULL)
+ cmd = default_command;
+
+ sx = 80;
+ sy = 25;
+ if (!data->flag_detached) {
+ sx = c->sx;
+ sy = c->sy;
+ }
if (sy < status_lines)
@@ -133,17 +149,15 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
- cmd = data->cmd;
- if (cmd == NULL)
- cmd = default_command;
- c->session = session_create(data->name, cmd, c->sx, sy);
- if (c->session == NULL)
+ if ((s = session_create(data->name, cmd, sx, sy)) == NULL)
fatalx("session_create failed");
if (data->winname != NULL) {
- xfree(c->session->curw->window->name);
- c->session->curw->window->name = xstrdup(data->winname);
+ xfree(s->curw->window->name);
+ s->curw->window->name = xstrdup(data->winname);
}
- if (data->flag_detached)
- server_write_client(c, MSG_EXIT, NULL, 0);
- else {
+ if (data->flag_detached) {
+ if (c != NULL)
+ server_write_client(c, MSG_EXIT, NULL, 0);
+ } else {
+ c->session = s;
server_write_client(c, MSG_READY, NULL, 0);
diff --git a/cmd-new-window.c b/cmd-new-window.c
index c1933d0..c45b601 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -102,3 +102,3 @@ cmd_new_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index f1e2b5b..496235a 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -81,3 +81,3 @@ cmd_rename_session_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index a21832f..b8838cf 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -91,3 +91,3 @@ cmd_rename_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-select-window.c b/cmd-select-window.c
index ed67f34..3cb29fa 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -100,3 +100,3 @@ cmd_select_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index 4e73b1f..d3c27e2 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -97,3 +97,3 @@ cmd_send_keys_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-set-option.c b/cmd-set-option.c
index ddd7a66..60dc596 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -81,3 +81,3 @@ cmd_set_option_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-swap-window.c b/cmd-swap-window.c
index b6ffb01..e7b02bd 100644
--- a/cmd-swap-window.c
+++ b/cmd-swap-window.c
@@ -103,3 +103,3 @@ cmd_swap_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index f906c51..ef375a3 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -82,3 +82,3 @@ cmd_switch_client_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index f036333..de2ade2 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -77,3 +77,3 @@ cmd_unbind_key_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index b3045d4..78adb8d 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -87,3 +87,3 @@ cmd_unlink_window_parse(
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
diff --git a/cmd.c b/cmd.c
index 42e6a90..5f5a93c 100644
--- a/cmd.c
+++ b/cmd.c
@@ -53,2 +53,3 @@ const struct cmd_entry *cmd_table[] = {
&cmd_set_option_entry,
+ &cmd_start_server_entry,
&cmd_swap_window_entry,
@@ -130,3 +131,3 @@ ambiguous:
usage:
- usage(cause, "%s %s", entry->name, entry->usage);
+ xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
return (NULL);
diff --git a/server.c b/server.c
index cc3270e..df1aecb 100644
--- a/server.c
+++ b/server.c
@@ -57,3 +57,3 @@ void server_lost_window(struct window *);
/* Fork new server. */
-int
+pid_t
server_start(const char *path)
@@ -64,5 +64,6 @@ server_start(const char *path)
int n, fd, mode;
+ pid_t pid;
char *cause;
- switch (fork()) {
+ switch (pid = fork()) {
case -1:
@@ -72,3 +73,3 @@ server_start(const char *path)
default:
- return (0);
+ return (pid);
}
@@ -79,2 +80,12 @@ server_start(const char *path)
+ ARRAY_INIT(&windows);
+ ARRAY_INIT(&clients);
+ ARRAY_INIT(&sessions);
+ key_bindings_init();
+
+ if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
+ log_warnx("%s", cause);
+ exit(1);
+ }
+
logfile("server");
@@ -112,9 +123,2 @@ server_start(const char *path)
- /* Load configuration. */
- if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
- log_warnx("%s", cause);
- xfree(cause);
- exit(1);
- }
-
if (daemon(1, 1) != 0)
@@ -122,3 +126,3 @@ server_start(const char *path)
log_debug("server daemonised, pid now %ld", (long) getpid());
-
+
n = server_main(path, fd);
@@ -139,8 +143,2 @@ server_main(const char *srv_path, int srv_fd)
siginit();
-
- ARRAY_INIT(&windows);
- ARRAY_INIT(&clients);
- ARRAY_INIT(&sessions);
-
- key_bindings_init();
diff --git a/session.c b/session.c
index 2834fdc..64e0fd8 100644
--- a/session.c
+++ b/session.c
@@ -119,2 +119,4 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
+ log_debug("session %s created", s->name);
+
return (s);
@@ -128,2 +130,4 @@ session_destroy(struct session *s)
+ log_debug("session %s destroyed", s->name);
+
if (session_index(s, &i) != 0)
diff --git a/tmux.c b/tmux.c
index 98f0091..ac0e7fb 100644
--- a/tmux.c
+++ b/tmux.c
@@ -55,21 +55,11 @@ u_int status_lines;
void sighandler(int);
+__dead void usage(void);
-void
-usage(char **ptr, const char *fmt, ...)
+__dead void
+usage(void)
{
- char *msg;
- va_list ap;
-
-#define USAGE "usage: %s [-v] [-f file] [-S socket-path]"
- if (fmt == NULL) {
- xasprintf(ptr, USAGE " command [flags]", __progname);
- } else {
- va_start(ap, fmt);
- xvasprintf(&msg, fmt, ap);
- va_end(ap);
-
- xasprintf(ptr, USAGE " %s", __progname, msg);
- xfree(msg);
- }
-#undef USAGE
+ fprintf(stderr,
+ "usage: %s [-v] [-f file] [-S socket-path] command [flags]",
+ __progname);
+ exit(1);
}
@@ -204,3 +194,3 @@ main(int argc, char **argv)
default:
- goto usage;
+ usage();
}
@@ -210,3 +200,3 @@ main(int argc, char **argv)
if (argc == 0)
- goto usage;
+ usage();
@@ -277,4 +267,2 @@ main(int argc, char **argv)
if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) {
- if (cause == NULL)
- goto usage;
log_warnx("%s", cause);
@@ -356,7 +344,2 @@ out:
return (n);
-
-usage:
- usage(&cause, NULL);
- fprintf(stderr, "%s\n", cause);
- exit(1);
}
diff --git a/tmux.h b/tmux.h
index 3e4fcab..b146909 100644
--- a/tmux.h
+++ b/tmux.h
@@ -695,3 +695,2 @@ extern u_int history_limit;
extern u_int status_lines;
-void usage(char **, const char *, ...);
void logfile(const char *);
@@ -761,2 +760,3 @@ extern const struct cmd_entry cmd_send_prefix_entry;
extern const struct cmd_entry cmd_set_option_entry;
+extern const struct cmd_entry cmd_start_server_entry;
extern const struct cmd_entry cmd_swap_window_entry;
@@ -811,3 +811,3 @@ const char *key_string_lookup_key(int);
extern struct clients clients;
-int server_start(const char *);
+pid_t server_start(const char *);