I make heavy use of screen's "log" command to log the output of a session to a file, when I am making changes in a given environment. I searched through tmux's man page, but couldn't find an equivalent. Is anyone aware of a similar feature in tmux, or do I have to write my own wrapper scripts to do this?
EDIT: I'm aware of 'script' and other utilities that allow me to log a session. The reason that screen's functionality is so useful is the ability to define a logfile variable which uses string escapes to uniquely identify each session.
e.g. I have a shell function which, given a hostname, will SSH to that host in a new screen window and set the window title to the hostname. When I start a log of that session, it is prefixed with the window title.
If this functionality doesn't exist in tmux, I'll have to create a new set of shell functions to set up 'scripts' of sessions I want to log. This isn't hugely difficult, but it may not be worth the effort given that screen does exactly what I need already.
Best Answer
Let me see if I have deciphered your screen configuration correctly:
logfile "%t-screen.log"
(probably in a.screenrc
file) to configure the name of the log file that will be started later.title <hostname>
(C-a A) screen command to set the title of a new window, oryou do
screen -t <hostname> ssh0 <hostname>
to start a new screen session.If so, then is nearly equivalent (requires tmux 1.3+ to support #W in the
pipe-pane
shell command;pipe-pane
is available in tmux 1.0+):In a configuration file (e.g.
.tmux.conf
):tmux rename-window <hostname>
(C-b ,) to rename an existing window, oruse
tmux new-window -n <hostname> 'ssh <hostname>'
to start a new tmux window, oruse
tmux new-session -n <hostname> 'ssh <hostname>'
to start a new tmux session.There is no notification that the log has been toggled, but you could add one if you wanted:
Note: The above line is shown as if it were in a configuration file (either
.tmux.conf
or one yousource
). tmux needs to see both the backslash and the semicolon; if you want to configure this from the a shell (e.g.tmux bind-key …
), then you will have to escape or quote both characters appropriately so that they are delivered to tmux intact. There does not seem to be a convenient way to show different messages for toggling on/off when using only a single binding (you might be able to rig something up withif-shell
, but it would probably be ugly). If two bindings are acceptable, then try this: