Tmux Shortcut – How to Go Read Only in Tmux

terminal-multiplexertmux

I've been using screen for years now as a way of ensuring that any remote work is safely kept open in after disconnects/crashes. In fact, as a matter of course, I use screens even when working locally.

Recently, my requirements have progressed to the stage that I switched to tmux because of the beauty of:

tmux attach -r

Attaching to my own sessions in readonly mode (-r) means that I don't have to worry about accidentally:

  • pasting lines of garbage in IRC
  • halting an important compile/deploy process
  • typing a password in full view for passersby

Of course the issue is that I have to open a session, C-b + d to detach, and then reopen it with the -r flag to go readonly. And then, when I occasionally want to chime in to an IRC conversation, interrupt a task or anything else, I have to detach again and reconnect normally.

Does anyone know of a way to make a key binding to switch between modes?

Best Answer

Not according to the man page, which only calls out the attach -r option to enable read-only mode.

Also, in the source code, only the following line in cmd-attach-session.c sets the read only flag. The rest of the code checks whether this flag is set, but does not change its value. So again, it looks like you are out of luck unless you can make (or request) a code change:

    if (cmd_check_flag(data->chflags, 'r'))
        ctx->cmdclient->flags |= CLIENT_READONLY;
Related Question