summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--Makefile5
-rw-r--r--TODO2
-rw-r--r--cmd-has-session.c51
-rw-r--r--cmd.c3
-rw-r--r--examples/nicm-start-tmux.sh6
-rw-r--r--tmux.h3
7 files changed, 67 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index eea231b1..a7e64ead 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+25 October 2007
+
+* (nicm) has-session command: checks if session exists.
+
24 October 2007
* (nicm) Support for \e6n to request cursor position. resize(1) now works.
@@ -159,5 +163,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.50 2007-10-24 15:29:27 nicm Exp $
+$Id: CHANGES,v 1.51 2007-10-25 17:44:24 nicm Exp $
diff --git a/Makefile b/Makefile
index a99357cc..79cc34b6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.30 2007-10-23 09:36:19 nicm Exp $
+# $Id: Makefile,v 1.31 2007-10-25 17:44:24 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean
@@ -23,7 +23,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
cmd-list-windows.c cmd-attach-session.c cmd-send-prefix.c \
- cmd-refresh-session.c cmd-kill-window.c cmd-list-clients.c
+ cmd-refresh-session.c cmd-kill-window.c cmd-list-clients.c \
+ cmd-has-session.c
YACC= yacc -d
diff --git a/TODO b/TODO
index 32229701..d58f333e 100644
--- a/TODO
+++ b/TODO
@@ -43,7 +43,6 @@
kill-window to limit accidental presses
- status-fg/status-bg should be to set attributes: bold, etc
- show-options command
-- fix resize(1)
- detach client and other client commands. note that there can only be a
"current client" on key presses - these should act like detach-session -
-a will do all clients, otherwise do nothing unless key in which case do
@@ -51,6 +50,7 @@
- check handling of out-of-bound values in input.c, most should be limited
rather than ignored
- save/restore (DECSC/DECRC) are ugly. maybe a struct screen_attr and memcpy
+- force maximum terminal size (centred?)
-- For 0.1 --------------------------------------------------------------------
- man page
diff --git a/cmd-has-session.c b/cmd-has-session.c
new file mode 100644
index 00000000..3369ccc4
--- /dev/null
+++ b/cmd-has-session.c
@@ -0,0 +1,51 @@
+/* $Id: cmd-has-session.c,v 1.1 2007-10-25 17:44:24 nicm Exp $ */
+
+/*
+ * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <getopt.h>
+#include <string.h>
+
+#include "tmux.h"
+
+/*
+ * 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.
+ */
+
+void cmd_has_session_exec(void *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_has_session_entry = {
+ "has-session", "has", "",
+ 0,
+ NULL,
+ cmd_has_session_exec,
+ NULL,
+ NULL,
+ NULL
+};
+
+void
+cmd_has_session_exec(unused void *ptr, struct cmd_ctx *ctx)
+{
+ struct client *c = ctx->client;
+
+ if (!(ctx->flags & CMD_KEY))
+ server_write_client(c, MSG_EXIT, NULL, 0);
+}
diff --git a/cmd.c b/cmd.c
index 791fdd92..da3370a5 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.19 2007-10-23 09:36:19 nicm Exp $ */
+/* $Id: cmd.c,v 1.20 2007-10-25 17:44:24 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,6 +27,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_attach_session_entry,
&cmd_bind_key_entry,
&cmd_detach_session_entry,
+ &cmd_has_session_entry,
&cmd_kill_window_entry,
&cmd_last_window_entry,
&cmd_list_clients_entry,
diff --git a/examples/nicm-start-tmux.sh b/examples/nicm-start-tmux.sh
index f4f8fb07..ebc40f94 100644
--- a/examples/nicm-start-tmux.sh
+++ b/examples/nicm-start-tmux.sh
@@ -7,7 +7,7 @@ SESSION=natasha-main
TMUX="tmux -S $SOCKET"
-if ! $TMUX -s $SESSION attach 2>/dev/null; then
+if ! $TMUX -s $SESSION has 2>/dev/null; then
$TMUX new -d -s $SESSION -nyelena 'exec ssh yelena' # 0
$TMUX set default-command "$SHELL -l"
@@ -27,6 +27,6 @@ if ! $TMUX -s $SESSION attach 2>/dev/null; then
$TMUX bind ^A send-prefix
$TMUX set bell-action none
-
- $TMUX -s $SESSION attach
fi
+
+$TMUX -s $SESSION attach
diff --git a/tmux.h b/tmux.h
index 54998e44..fc02963c 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.69 2007-10-24 15:40:59 nicm Exp $ */
+/* $Id: tmux.h,v 1.70 2007-10-25 17:44:24 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -531,6 +531,7 @@ char *cmd_recv_string(struct buffer *);
extern const struct cmd_entry cmd_attach_session_entry;
extern const struct cmd_entry cmd_bind_key_entry;
extern const struct cmd_entry cmd_detach_session_entry;
+extern const struct cmd_entry cmd_has_session_entry;
extern const struct cmd_entry cmd_kill_window_entry;
extern const struct cmd_entry cmd_last_window_entry;
extern const struct cmd_entry cmd_list_clients_entry;