From 9f06104c3a56ad5ea2070317b776dfa84f213ffb Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 25 Oct 2007 17:44:25 +0000 Subject: [PATCH] has-session command. --- CHANGES | 6 ++++- Makefile | 5 ++-- TODO | 2 +- cmd-has-session.c | 51 +++++++++++++++++++++++++++++++++++++ cmd.c | 3 ++- examples/nicm-start-tmux.sh | 6 ++--- tmux.h | 3 ++- 7 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 cmd-has-session.c 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 + * + * 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 + +#include +#include + +#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 @@ -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 @@ -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;