Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#50 When detaching, show session-name in exit msg

closed
2015-02-09
2013-07-23
T. Perkins
No

I used to use gnu screen and it would display session details after a detach, like so:

[detached from 18352.pts-4.remote]

If I quit ssh but leave the xterm running, then, when I return (i.e. after my lunch break), it's easy to reattach later like so:

ssh remote
  screen -RD 18352.pts-4.remote

I just copy/paste the session details.

With tmux, after a detach, we only see:

[detached]

I would prefer to see (this is my "feature request"):

[detached from 16]

I do not name my sessions as I don't want to have to memorize my session names, so I have to do an extra step to find out what the session-name of the session I detached from was. Not terrible, but less convenient than having tmux just display it upon detach...

Thanks for your time and consideration!

Related

Tickets: #50

Discussion

  • Try this please:

    diff --git a/client.c b/client.c
    index b9e3b30..434b904 100644
    --- a/client.c
    +++ b/client.c
    @@ -48,6 +48,7 @@ enum {
    } client_exitreason = CLIENT_EXIT_NONE;
    int client_exitval;
    enum msgtype client_exittype;
    +const char *client_exitsession;
    int client_attached;

    int client_get_lock(char );
    @@ -138,12 +139,24 @@ failed:
    const char

    client_exit_message(void)
    {
    + static char msg[256];
    +
    switch (client_exitreason) {
    case CLIENT_EXIT_NONE:
    break;
    case CLIENT_EXIT_DETACHED:
    + if (client_exitsession != NULL) {
    + xsnprintf(msg, sizeof msg, "detached "
    + "(from session %s)", client_exitsession);
    + return (msg);
    + }
    return ("detached");
    case CLIENT_EXIT_DETACHED_HUP:
    + if (client_exitsession != NULL) {
    + xsnprintf(msg, sizeof msg, "detached and SIGHUP "
    + "(from session %s)", client_exitsession);
    + return (msg);
    + }
    return ("detached and SIGHUP");
    case CLIENT_EXIT_LOST_TTY:
    return ("lost tty");
    @@ -542,14 +555,16 @@ client_dispatch_wait(void *data)
    fatalx("bad MSG_STDOUT");
    memcpy(&stdoutdata, imsg.data, sizeof stdoutdata);

    • client_write(STDOUT_FILENO, stdoutdata.data, stdoutdata.size);
    • client_write(STDOUT_FILENO, stdoutdata.data,
    • stdoutdata.size);
      break;
      case MSG_STDERR:
      if (datalen != sizeof stderrdata)
      fatalx("bad MSG_STDERR");
      memcpy(&stderrdata, imsg.data, sizeof stderrdata);

    • client_write(STDERR_FILENO, stderrdata.data, stderrdata.size);

    • client_write(STDERR_FILENO, stderrdata.data,
    • stderrdata.size);
      break;
      case MSG_VERSION:
      if (datalen != 0)
      @@ -592,6 +607,7 @@ client_dispatch_attached(void)
      {
      struct imsg imsg;
      struct msg_lock_data lockdata;
    • struct msg_detach_data ddata;
      struct sigaction sigact;
      ssize_t n, datalen;

    @@ -606,9 +622,18 @@ client_dispatch_attached(void)
    switch (imsg.hdr.type) {
    case MSG_DETACHKILL:
    case MSG_DETACH:
    - if (datalen != 0)
    + if (datalen != 0 &&
    + datalen != sizeof (struct msg_detach_data))
    fatalx("bad MSG_DETACH size");

    • if (datalen == sizeof (struct msg_detach_data)) {
    • memcpy(&ddata, imsg.data,
    • sizeof ddata);
    • ddata.s[(sizeof ddata.s) - 1] = '\0';
    • if (*ddata.s != '\0')
    • client_exitsession = xstrdup(ddata.s);
    • }
      +
      client_exittype = imsg.hdr.type;
      if (imsg.hdr.type == MSG_DETACHKILL)
      client_exitreason = CLIENT_EXIT_DETACHED_HUP;
      diff --git a/cmd-attach-session.c b/cmd-attach-session.c
      index 0718573..28dd957 100644
      --- a/cmd-attach-session.c
      +++ b/cmd-attach-session.c
      @@ -19,6 +19,7 @@
      #include <sys types.h="">

    #include <stdlib.h>
    +#include <string.h>

    #include "tmux.h"

    @@ -41,11 +42,12 @@ const struct cmd_entry cmd_attach_session_entry = {
    enum cmd_retval
    cmd_attach_session(struct cmd_q cmdq, const char tflag, int dflag, int rflag)
    {
    - struct session s;
    - struct client
    c;
    - const char update;
    - char
    cause;
    - u_int i;
    + struct session s;
    + struct client
    c;
    + const char update;
    + char
    cause;
    + u_int i;
    + struct msg_detach_data data;

    if (RB_EMPTY(&sessions)) {
        cmdq_error(cmdq, "no sessions");
    

    @@ -70,7 +72,11 @@ cmd_attach_session(struct cmd_q cmdq, const char tflag, int dflag, int rflag)
    continue;
    if (c == cmdq->client)
    continue;
    - server_write_client(c, MSG_DETACH, NULL, 0);
    + if (strlcpy(data.s, c->session->name,
    + sizeof data.s) >= sizeof data.s)
    + *data.s = '\0';
    + server_write_client(c, MSG_DETACH, &data,
    + sizeof data);
    }
    }

    @@ -89,8 +95,13 @@ cmd_attach_session(struct cmd_q cmdq, const char tflag, int dflag, int rflag)
    if (rflag)
    cmdq->client->flags |= CLIENT_READONLY;

    • if (dflag)
    • server_write_session(s, MSG_DETACH, NULL, 0);
    • if (dflag) {
    • if (strlcpy(data.s, c->session->name, sizeof data.s)
    • = sizeof data.s)

    • *data.s = '\0';
    • server_write_session(s, MSG_DETACH, &data,
    • sizeof data);
    • }

      update = options_get_string(&s->options, "update-environment");
      environ_update(update, &cmdq->client->environ, &s->environ);
      

      diff --git a/cmd-detach-client.c b/cmd-detach-client.c
      index 6e00e07..2c71fa6 100644
      --- a/cmd-detach-client.c
      +++ b/cmd-detach-client.c
      @@ -18,6 +18,8 @@

    #include <sys types.h="">

    +#include <string.h>
    +
    #include "tmux.h"

    /
    @@ -39,11 +41,12 @@ const struct cmd_entry cmd_detach_client_entry = {
    enum cmd_retval
    cmd_detach_client_exec(struct cmd
    self, struct cmd_q cmdq)
    {
    - struct args
    args = self->args;
    - struct client c, c2;
    - struct session s;
    - enum msgtype msgtype;
    - u_int i;
    + struct args
    args = self->args;
    + struct client c, c2;
    + struct session *s;
    + enum msgtype msgtype;
    + u_int i;
    + struct msg_detach_data data;

    if (args_has(args, 'P'))
        msgtype = MSG_DETACHKILL;
    

    @@ -57,8 +60,12 @@ cmd_detach_client_exec(struct cmd self, struct cmd_q cmdq)

        for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
            c = ARRAY_ITEM(&clients, i);
    
    • if (c != NULL && c->session == s)
    • server_write_client(c, msgtype, NULL, 0);
    • if (c == NULL || c->session != s)
    • continue;
    • if (strlcpy(data.s, c->session->name, sizeof data.s)
    • = sizeof data.s)

    • *data.s = '\0';
    • server_write_client(c, msgtype, &data, sizeof data);
      }
      } else {
      c = cmd_find_client(cmdq, args_get(args, 't'), 0);
      @@ -70,10 +77,18 @@ cmd_detach_client_exec(struct cmd self, struct cmd_q cmdq)
      c2 = ARRAY_ITEM(&clients, i);
      if (c2 == NULL || c == c2)
      continue;
    • server_write_client(c2, msgtype, NULL, 0);
    • if (strlcpy(data.s, c2->session->name,
    • sizeof data.s) >= sizeof data.s)
    • *data.s = '\0';
    • server_write_client(c2, msgtype, &data,
    • sizeof data);
      }
    • } else
    • server_write_client(c, msgtype, NULL, 0);
    • } else {
    • if (strlcpy(data.s, c->session->name, sizeof data.s)
    • = sizeof data.s)

    • *data.s = '\0';
    • server_write_client(c, msgtype, &data, sizeof data);
    • }
      }

      return (CMD_RETURN_STOP);
      diff --git a/tmux.h b/tmux.h
      index cc1c79e..8d98496 100644
      --- a/tmux.h
      +++ b/tmux.h
      @@ -499,6 +499,10 @@ struct msg_exit_data {
      int retcode;
      };

    +struct msg_detach_data {
    + char s[128];
    +};
    +
    struct msg_stdin_data {
    ssize_t size;
    char data[BUFSIZ];

    On Tue, Jul 23, 2013 at 06:46:42PM +0000, T. Perkins wrote:


    [1][tickets:#50] When detaching, show session-name in exit msg

    Status: open
    Labels: detach session-name
    Created: Tue Jul 23, 2013 06:46 PM UTC by T. Perkins
    Last Updated: Tue Jul 23, 2013 06:46 PM UTC
    Owner: Nicholas Marriott

    I used to use gnu screen and it would display session details after a
    detach, like so:

    [detached from 18352.pts-4.remote]

    If I quit ssh but leave the xterm running, then, when I return (i.e. after
    my lunch break), it's easy to reattach later like so:

    ssh remote
    screen -RD 18352.pts-4.remote

    I just copy/paste the session details.

    With tmux, after a detach, we only see:

    [detached]

    I would prefer to see (this is my "feature request"):

    [detached from 16]

    I do not name my sessions as I don't want to have to memorize my session
    names, so I have to do an extra step to find out what the session-name of
    the session I detached from was. Not terrible, but less convenient than
    having tmux just display it upon detach...

    Thanks for your time and consideration!


    Sent from sourceforge.net because you indicated interest in
    [2]https://sourceforge.net/p/tmux/tickets/50/

    To unsubscribe from further messages, please visit
    [3]https://sourceforge.net/auth/subscriptions/

    References

    Visible links
    1. http://sourceforge.net/p/tmux/tickets/50/
    2. https://sourceforge.net/p/tmux/tickets/50/
    3. https://sourceforge.net/auth/subscriptions/

     

    Related

    Tickets: #50

  • Thomas Adam
    Thomas Adam
    2013-10-13

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,3 @@
    -
     I used to use gnu screen and it would display session details after a detach, like so:
    
         [detached from 18352.pts-4.remote]
    
    • status: open --> closed
    • Milestone: -->
     
  • Thomas Adam
    Thomas Adam
    2013-10-13

    This will be in 1.9