
Tmux Resurrect – Persists tmux environment across system restarts - andars
https://github.com/tmux-plugins/tmux-resurrect
======
avolcano
I've been using this for a few months, since for some reason my work Macbook
really likes to crash when it goes into sleep mode (have a feeling it's
related to our Vagrant/VMWare setup, but haven't had a chance to investigate).
It works better than any similar tmux plugin I've tried, and is dead-simple to
use.

I particularly like that there's a "whitelist" of which running commands it
will restore, so I can e.g. restore both VIM sessions and my Webpack watchers
when I restore my session.

~~~
lobster_johnson
If you're on OS X Yosemite, the "sleep wake failure" problem is a well-known
issue that is (probably) not hardware-related. I have it, my colleagues (some
of whom have brand new machines) have it, and it's probably what you are
affected by.

The symptom is that the machine will frequently reboot instead of coming out
of sleep. From the looks of things, it's related to the 70-minute sleep-to-
standby setting (where the machine will turn itself off), which can be changed
with "pmset".

------
OJFord
Considering that I recently ran home with a rapidly flattening battery -
precisely so that I would not lost my session - I am very pleased to find this
here :D

~~~
iso8859-1
why not hibernate?

~~~
OJFord
Mac. Does sleep when battery flat, rather than "die" completely - but how long
do you trust it for? Knowing Sod's Law, I opted for the run.

~~~
mikeash
Newer Macs will save the memory to nonvolatile storage so they can withstand
total power loss. The question of trustworthiness remains, though.

~~~
rcthompson
My experience with my Macbook is that around 20% battery, it just dies. No
sleep, no hibernate, it just goes completely dark and when I plug it back in
it has to boot from scratch.

~~~
mikeash
Sounds like you have a bad battery or something like that, which is causing
the battery meter to be inaccurate and is thus interfering with the rest of
the process. To safely sleep/hibernate your machine the system has to have a
pretty good idea of just how much energy is left in the battery, since it has
to initiate the process before the battery goes completely flat. On a properly
working machine, you should get all the way down to 0%, and then it will
forcibly sleep if you don't do it yourself.

Have you tried an SMC reset? That's the low-level whatnot that controls the
battery, and sometimes it can get confused.

~~~
rcthompson
I tried an SMC reset today, and it changed nothing. It still just dies right
around 20%. (At least, I _think_ I reset the SMC. There wasn't any obvious
feedback confirming that I had done so.)

~~~
mikeash
Yeah, the SMC reset procedure is pretty opaque. Sounds like you're probably at
the point of needing a repair. Hope you're in warranty, although given how
these things go I imagine you're probably not.

~~~
rcthompson
Nah, I've had it a few years, so it's out of warranty. I'll probably have to
replace the battery eventually. I don't mind if the battery's capacity is
decreasing, I just want it to auto-sleep before the battery dies. Maybe
there's a way to set the auto-sleep threshold to 25% or something?

------
manish_gill
I _love_ this plugin. Usually, my mac stays online for days and even weeks,
but any time I go down (or for some certain software updates when I have to
restart it), it really sucks to lose all your environmental setup.

I combine it with a few lines of code in my ~/.zshrc to automatically enter
the virtualenv for the current directory. Works out really nice! :)

~~~
baby
there's a oh-my-zsh plugin for that

------
davvolun
Been using tmux resurrect for awhile now and I love it...one thing occurs to
me though: does anyone have a hack to automatically save my tmux session on
disconnect?

Edit: ahha, not exactly what I asked for, but linked on the tmux-resurrect
page is tmux-continuum, automatic saving of tmux sessions. Perfect for me.

~~~
pdexter
Wait... what? That's the whole point of tmux. As far as I know there's no such
thing as 'saving'. They're automatically saved. Unless you're on a shared
computer? If so... here's a solution I wrote up a while ago:

\--- title: Tmux on a shared server \---

Normally, tmux stores its session sockets in the /tmp directory. This is bad
news when trying to run tmux on a shared computer (e.g. shared compute nodes)
since the tmp directory is probably cleared on every login. To get around this
tmux offers a way to store session sockets in alternative locations. How to
use this isn't entirely clear in the man page though, so I'll outline it here.
First, I'll create a directory to store the socket with ``mkdir
~/.tmux.socket'`{.bash}. Tmux stores new session sockets in the tmp directory
so we must change that when we start tmux:

    
    
      TMPDIR=~/.tmux.socket tmux
    

and to attach to this socket we use the `-S`{.bash} option and glob to the
socket (defaulted to be named `default`{.bash})

    
    
      tmux -S ~/.tmux.socket/*/default attach
    
    

Here are some aliases to put into your shell config file to help:

    
    
      alias tmux-start="TMPDIR=~/.tmux.socket tmux"
      alias tmux-attach="tmux -S ~/.tmux.socket/*/default attach"

~~~
farresito
He probably means saving on computer shutdown or reboot.

------
pcl
I wrote a far more basic zsh config script that integrates with OSX's
Terminal.app window restoration to restore the current working directory in
each tab after quit / relaunch. Between that and browser tab restoration on
reboot, I don't mind the occasional restart any more.

[https://gist.github.com/pcl/f2c6a6f6f193400eeaa6](https://gist.github.com/pcl/f2c6a6f6f193400eeaa6)

~~~
baby
I don't have a .zsh.d folder but a .oh-my-zsh folder

Where do I put your script?

~~~
kornish
You should be able to drop it in ~/.oh-my-zsh/custom and have it run
automatically upon terminal login.

------
TomAnthony
I gave up on tmux on my Mac, as I mainly used it with teamocil to have saved
layouts of panes and commands, but I never disconnected from it. I found quite
a few people use it this way.

I wrote iTermocil[2] to replicate the functionality of teamocil natively in
iTerm2, so I could have all the upsides (from my POV) but keep native UI
elements etc.

[1]
[https://github.com/TomAnthony/itermocil](https://github.com/TomAnthony/itermocil)

~~~
graffitici
I didn't know about Teamocil, I use Tmuxinator for the same purpose. The
latter seems to have more stars on GH, any reason why prefer the former?

~~~
TomAnthony
Simple because I came across teamocil first, as someone recommended it to me.
It is actually teamocil that led me to tmux!

I have since come across tmuxinator, which is almost identical, but from my
reading of tmuxinators docs it seems it is more flexible in how you can
configure it.

I'm adding tmuxinator support to iTermocil. :)

~~~
graffitici
Brilliant, looking forward!

------
Galanwe
Is it also able to restore ssh session? Like, host and working directory at
least?

~~~
fphilipe
By default it only restores a program that is whitelisted, such as vim, man,
etc. You could, I guess, tell it to also restore ssh sessions. Here's a guide
on how to do that: [https://github.com/tmux-plugins/tmux-
resurrect/blob/master/d...](https://github.com/tmux-plugins/tmux-
resurrect/blob/master/docs/restoring_programs.md)

~~~
Galanwe
Will have a look, thanks. I was dreaming of something that could restore tmux
sessions, along with its ssh connections, and the vim inside the ssh :D seems
like christmas is not for today.

~~~
icebraining
You could use a bastion host to run the tmux. If your client machine were to
disconnect/reboot, the bastion host would keep the sessions open. You'd just
need to login to it and re-attach tmux.

------
abledon
Has anyone here ported from Tmuxinator to Tmux Resurrect? Was it a Success?

~~~
brunosutic
Just in case you missed it, there's a guide how to migrate from tmuxinator to
tmux-resurrect:

[https://github.com/tmux-plugins/tmux-
resurrect/blob/master/d...](https://github.com/tmux-plugins/tmux-
resurrect/blob/master/docs/migrating_from_tmuxinator.md)

~~~
flyingyeti
I read that, but as a rather heavy user of tmuxinator, I wouldn't really want
to have _all_ my projects running in the background at all times. I like that
with tmuxinator, I can just start up the project(s) I'm currently working on,
and leave the rest idle.

I am going to try out tmux-resurrect, but it's value to me would be mostly for
ad-hoc tmux sessions; I think I'll still set up dedicated tmuxinator configs
for each of my longer term projects.

------
mzs
Thanks for this!

I've done something horrible in the past when I knew about coming rolling
power outages - snapshoting virtual box. It worked but was sort of annoying.

------
MoSal
This is the greatest thing since ... tmux.

If only @resurrect-save-zsh-history was implemented.

------
baby
What I don't like is that you have to manually save/restore every time.

~~~
brunosutic
There is tmux-continuum that works with resurrect to automate
saving/restoring.

[https://github.com/tmux-plugins/tmux-continuum](https://github.com/tmux-
plugins/tmux-continuum)

