
Show HN: Restore tmux environment after a system restart - brunosutic
https://github.com/tmux-plugins/tmux-resurrect
======
pixelmonkey
I also really love tmuxp, which lets you save tmux sessions as json files and
save/reload them later. Great for setting up tmux sessions for different
workflows.

[http://tmuxp.readthedocs.org/](http://tmuxp.readthedocs.org/)

------
kacy
Holy. Wow. This is the most exciting thing that I've seen this weekend. I've
created hacks on hacks to get around this problem. I'm SO happy about this!
Thank you!

------
Bootvis
I've visited HN for a long time and this is the first submission I can say of:

I need this in my life.

Thanks

------
ixtli
Great! Now can someone tell me how to configure tmux so that I can have two
connected term emulators use multiple virtual consoles in one session? Screen
allows you to do this and I've been searching for a way to get tmux to behave
the same way.

(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.)

~~~
pyre
Shameless plug:
[https://github.com/bsandrow/tmux.sh](https://github.com/bsandrow/tmux.sh)

I wrote that in response to the last thread complaining about said feature
came up.

~~~
ixtli
well done. i'll have a go at making byobu execute this script instead of tmux
itself to see if that fixes things.

------
swah
BTW do people use tmux/screen to start multiple apps for development?

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).

~~~
JelteF
I just use a shell script based on this SO answer.
[https://stackoverflow.com/questions/9023164/in-bash-how-
can-...](https://stackoverflow.com/questions/9023164/in-bash-how-can-i-run-
multiple-infinitely-running-commands-and-cancel-them-all)

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.

~~~
swah
See the goreman solution below: its similar but each output line has its app
prefixed.

------
coderzach
Wow, this is great! I've gone weeks without software updates because I didn't
want to lose my tmux session.

------
ghshephard
I just installed it and played around with it for a bit - it's a really nice -
but what I would kill for is something that would restore tmux server state -
including the various scroll-back-buffers.

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](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! :-)

~~~
c0rner
There is such a tool here
[https://github.com/c0rner/scripts/blob/master/tmux_save](https://github.com/c0rner/scripts/blob/master/tmux_save)

------
golfadas
I thought session restore for tmux was awesome, and then I got to know that
tmux has a plugin manager and fuzzy history search! brunosutic, you made my
day.

------
spindritf
Great script and timing. For those who missed it, this was just requested on
HN yesterday
[https://news.ycombinator.com/item?id=8243157](https://news.ycombinator.com/item?id=8243157)

Screencast is a nice touch.

------
lobster_johnson
Tangentially, anyone know how to run tmux (or screen) so that SSH sessions
automatically attach?

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.

~~~
ams6110
I have this in my .kshrc, can't recall where I found it.

    
    
      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.

~~~
pyre
What is the point of this:

    
    
      "${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?

------
fest
This looks like a cool project, although I personally prefer separate tmux
sessions for each project.

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.

~~~
tlunter
It pretty clearly says it only runs a very small subset of commands.

"Only a conservative list of programs is restored by default: vi vim emacs man
less more tail top htop irssi."

~~~
brunosutic
Yes, and for the paraniod there's an option that disables restoring any
command.

------
thirdtruck
Thanks! I've been meaning to use tmux more and this will make it all the
easier.

------
0xeeeeeeee
This looks really cool. There are a lot of people (like me) who live in tmux
and I'm really surprised this hadn't been done earlier.

------
chengl
Cool stuff. But doesn't work for me. It's not saving when I press
prefix+Alt+s. Anyone with the same experience?

I'm on MBP, tmux 1.9a.

~~~
SeoxyS
Some terminal emulators are pretty weird about sending the Alt key. If you
open vim, in insert mode, and type <C-v><Alt-s>, it'll show you what is keys
are _actually_ being sent. If it's not what you expect, try remapping it to
something other than <Alt-s>.

------
cookiecaper
I was just looking for something like this a couple of weeks ago. Thanks for
sharing!

------
superfunc
sidenote: your terminal color setup is rad.

edit: I'd also like to say, I am really enjoying the trend of people including
a video demo of their applications.

