Show HN: Restore tmux environment after a system restart
github.com
github.com
I need this in my life.
Thanks
(In fact, I've had a real problem getting tmux to behave well at all when multiple term emulators are connected to the same session. I've had weird window resizing problems.)
tmux a -d
I wrote that in response to the last thread complaining about said feature came up.
tmux new-session -t <existing_session_name>
(Do a "tmux ls" to see existing sessions)
The one problem with this approach is that each session created this way (i.e. one that "attaches" to an existing session) actually creates a new "mirror" (?) session that will eventually clutter up your list of existing sessions.
My workaround is to create an initial named session (tmux new-session -s name), then attach to that named session. I never use "tmux ls" :p
You may also want to add "set-window-option -g aggressive-resize on" to your .tmux.conf (or prepend with "tmux" and run it in an existing session). To quote the manpage: "will resize the window to the size of the smallest session for which it is the current window, rather than the smallest session to which it is attached".
I'm looking for a way to start nginx/sass watcher/js builder/web app in a split screen, and also stop them all with one command (which would send ctrl-c to all windows). Now I just use tabs (OSX).
Ctrl-c worked like I was running a single app:
16:44:33 scss | QUIT
16:44:33 webpack | QUIT
16:44:33 nginx | QUIT
16:44:33 go | QUIT
This was better than expected! I suppose tmux will be preferable if one of the apps is slow to start and must be killed individually.The only sort of problem with it is that the output gets merged with each other. You can quite easily figure out what is what though.
One of the few reasons I still drop out of tmux, and switch over to Terminal.app (iTerm2 might do this as well natively) - is when you have a system crash or Kernel Panic (which happens all to often with OS X -weekly basis, or daily if I'm plugging/unplugging the USB -> Serial adapters), and OS X reboots - Terminal.app restores all of my history buffers - so I don't lose any of the work in my screens.
Yes, I know script is a good way of doing this - but When you are opening a dozen or so windows, it's nice to be able to just scroll back in your history to see what you are working on.
Saving the scroll-back buffer is possible, (https://github.com/tmux-plugins/tmux-logging) - I just don't know if there is any way of restoring it.
Even if I could just do this prior to doing something dangerous (like unplugging a USB cable), that would be great.
I just noticed, that both of these plugins are by the same developer, brunosutic, - so perhaps we'll see this feature in the future. If so, super excited! :-)
Screencast is a nice touch.
Ie., I want every interactive connection to automatically attach to a session on the server if one exists, otherwise create one, so that when I disconnect or quit, my shell stays.
I tried to hack a solution using .zshrc a while ago, but it just didn't work properly and/or didn't handle all the edge cases, I forget exactly.
if [ "$PS1" != "" -a "${STARTED_TMUX:-x}" = x -a "${SSH_TTY:-x}" != x ]
then
STARTED_TMUX=1; export STARTED_TMUX
sleep 1
( (tmux has-session -t remote && tmux attach-session -t remote) || (tmux new-session -s remote) ) && exit 0
echo "tmux failed to start"
fi
I also don't recall why the "sleep" command is in there.Edit: to clarify, this is in the .kshrc of my work machine. When I start xterms on that machine, they just get a normal shell because $SSH_TTY is not set. When I ssh into my work machine from elsewhere, I get attached to the tmux session (if any) or one is started.
"${STARTED_TMUX:-x}" = x
vs. -z "$STARTED_TMUX"
or "$STARTED_TMUX" = ""
It's always seemed like a legacy method of testing to empty string from a time when "" wouldn't be parsed as an argument. Is there any real reason to still do that today?Probably this issue? http://superuser.com/questions/629227/tmux-prints-12c-whenev...
EDIT: though I believe you'd need to have that on the server side.
Also, am I missing something, or does this really execute the last command for each pane/window which had a process other than shell running? I can imagine a few potentially dangerous situations if this is how it works.
"Only a conservative list of programs is restored by default: vi vim emacs man less more tail top htop irssi."
I'm on MBP, tmux 1.9a.
edit: I'd also like to say, I am really enjoying the trend of people including a video demo of their applications.