Grouped sessions don't share options so can't you just set
destroy-unattached for the transient sessions?


On Tue, Apr 16, 2013 at 09:56:20PM -0700, Daniel Ralston wrote:
> Hi all,
> 
> If I've done my job well, the commit message should be descriptive
> enough. Let me know if you'd like me to make any tweaks.
> 
> Have a good week!
>     Daniel
> 
> 
> ----
> >From 1e5676ea9420359e7de4ee49339a7d089fab7839 Mon Sep 17 00:00:00 2001
> From: Daniel Ralston <wubbul...@gmail.com>
> Date: Tue, 16 Apr 2013 20:09:17 -0700
> Subject: [PATCH] Add -T (make session "transient") option to new-session
> 
> Transient sessions will be killed when no clients are attached to them.
> 
> * Rationale:
> 
> When switching to tmux, many people miss screen's ability to have
> multiple clients attached to a single session, without every client
> having to share the same view.
> 
> tmux can approximate this behaviour by grouping clients' sessions using
> the -t option for new-session. But, each session that the user doesn't
> want anymore must be explicitly killed when its client is detached, or
> else the detached sessions will pile up in the background, unused. (One
> distasteful alternative is to use some sort of byzantine
> session-managing shell script.)
> 
> The -T option solves this problem. For example, to mimic screen's
> behaviour as discussed above, the user might create a "master" session
> that is always kept in the background. When sessions are grouped with
> the master session and flagged as transient, they are killed and tidied
> up properly when their clients detach. This is especially handy for
> preventing clutter when, for example, the user absent-mindedly closes a
> client's terminal, killing it with a SIGHUP.
> 
> Example:
> $ # Create the master session f necessary:
> $ tmux new-session -A -s TMUX_MASTER \; detach
> $ # Create the transient client:
> $ tmux -T -t TMUX_MASTER
> ---
>  cmd-new-session.c |  9 +++++++--
>  server.c          | 19 +++++++++++++++++++
>  tmux.1.in         |  7 ++++++-
>  tmux.h            |  1 +
>  4 files changed, 33 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd-new-session.c b/cmd-new-session.c
> index 4eebe63..0147933 100644
> --- a/cmd-new-session.c
> +++ b/cmd-new-session.c
> @@ -35,8 +35,8 @@ enum cmd_retval     cmd_new_session_exec(struct cmd
> *, struct cmd_q *);
> 
>  const struct cmd_entry cmd_new_session_entry = {
>      "new-session", "new",
> -    "AdDF:n:Ps:t:x:y:", 0, 1,
> -    "[-AdDP] [-F format] [-n window-name] [-s session-name] "
> +    "AdDF:n:Ps:t:Tx:y:", 0, 1,
> +    "[-AdDPT] [-F format] [-n window-name] [-s session-name] "
>      CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
>      CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
>      NULL,
> @@ -193,6 +193,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q 
> *cmdq)
>      }
>      environ_free(&env);
> 
> +    /* Flag the session as transient if the -T flag is given */
> +    if (args_has(args, 'T')) {
> +        s->flags |= SESSION_TRANSIENT;
> +    }
> +
>      /* Set the initial window name if one given. */
>      if (cmd != NULL && args_has(args, 'n')) {
>          w = s->curw->window;
> diff --git a/server.c b/server.c
> index 4bfa918..7af0673 100644
> --- a/server.c
> +++ b/server.c
> @@ -210,6 +210,7 @@ server_loop(void)
>          server_client_loop();
> 
>          key_bindings_clean();
> +        server_kill_transient();
>          server_clean_dead();
>      }
>  }
> @@ -258,6 +259,24 @@ server_send_shutdown(void)
>      }
>  }
> 
> +/* Kill all unattached sessions marked as transient. */
> +void
> +server_kill_transient(void)
> +{
> +    struct session *s, *next_s;
> +
> +    s = RB_MIN(sessions, &sessions);
> +    while (s != NULL) {
> +        next_s = RB_NEXT(sessions, &sessions, s);
> +        if ((s->flags & SESSION_UNATTACHED) &&
> +            (s->flags &     SESSION_TRANSIENT)) {
> +            printf("Whadda faaaa?");
> +            session_destroy(s);
> +        }
> +        s = next_s;
> +    }
> +}
> +
>  /* Free dead, unreferenced clients and sessions. */
>  void
>  server_clean_dead(void)
> diff --git a/tmux.1.in b/tmux.1.in
> index 98bf957..7797093 100644
> --- a/tmux.1.in
> +++ b/tmux.1.in
> @@ -672,7 +672,7 @@ command.
>  Lock all clients attached to
>  .Ar target-session .
>  .It Xo Ic new-session
> -.Op Fl AdDP
> +.Op Fl AdDPT
>  .Op Fl F Ar format
>  .Op Fl n Ar window-name
>  .Op Fl s Ar session-name
> @@ -740,6 +740,11 @@ are invalid if
>  is used.
>  .Pp
>  The
> +.Fl T
> +option makes the session "transient"; when all of its clients are
> +disconnected, it will be killed instead of detached.
> +.Pp
> +The
>  .Fl P
>  option prints information about the new session after it has been created.
>  By default, it uses the format
> diff --git a/tmux.h b/tmux.h
> index f0b9edf..714c38f 100644
> --- a/tmux.h
> +++ b/tmux.h
> @@ -1103,6 +1103,7 @@ struct session {
>      struct options     options;
> 
>  #define SESSION_UNATTACHED 0x1    /* not attached to any clients */
> +#define SESSION_TRANSIENT 0x2 /* kill session when unattached */
>      int         flags;
> 
>      struct termios    *tio;
> --
> 1.8.2.1
> 
> ------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable of advanced
> analytics on semi-structured data. The platform includes APIs for building
> apps and a phenomenal toolset for data science. Developers can use
> our toolset for easy data analysis & visualization. Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to