Giter Site home page Giter Site logo

tmux-resurrect's Introduction

Tmux Resurrect

Build Status

Restore tmux environment after system restart.

Tmux is great, except when you have to restart the computer. You lose all the running programs, working directories, pane layouts etc. There are helpful management tools out there, but they require initial configuration and continuous updates as your workflow evolves or you start new projects.

tmux-resurrect saves all the little details from your tmux environment so it can be completely restored after a system restart (or when you feel like it). No configuration is required. You should feel like you never quit tmux.

It even (optionally) restores vim and neovim sessions!

Automatic restoring and continuous saving of tmux env is also possible with tmux-continuum plugin.

Screencast

screencast screenshot

Key bindings

  • prefix + Ctrl-s - save
  • prefix + Ctrl-r - restore

About

This plugin goes to great lengths to save and restore all the details from your tmux environment. Here's what's been taken care of:

  • all sessions, windows, panes and their order
  • current working directory for each pane
  • exact pane layouts within windows (even when zoomed)
  • active and alternative session
  • active and alternative window for each session
  • windows with focus
  • active pane for each window
  • "grouped sessions" (useful feature when using tmux with multiple monitors)
  • programs running within a pane! More details in the restoring programs doc.

Optional:

Requirements / dependencies: tmux 1.9 or higher, bash.

Tested and working on Linux, OSX and Cygwin.

tmux-resurrect is idempotent! It will not try to restore panes or windows that already exist.
The single exception to this is when tmux is started with only 1 pane in order to restore previous tmux env. Only in this case will this single pane be overwritten.

Installation with Tmux Plugin Manager (recommended)

Add plugin to the list of TPM plugins in .tmux.conf:

set -g @plugin 'tmux-plugins/tmux-resurrect'

Hit prefix + I to fetch the plugin and source it. You should now be able to use the plugin.

Manual Installation

Clone the repo:

$ git clone https://github.com/tmux-plugins/tmux-resurrect ~/clone/path

Add this line to the bottom of .tmux.conf:

run-shell ~/clone/path/resurrect.tmux

Reload TMUX environment with: $ tmux source-file ~/.tmux.conf. You should now be able to use the plugin.

Docs

Configuration

Optional features

Other goodies

  • tmux-copycat - a plugin for regex searches in tmux and fast match selection
  • tmux-yank - enables copying highlighted text to system clipboard
  • tmux-open - a plugin for quickly opening highlighted file or a url
  • tmux-continuum - automatic restoring and continuous saving of tmux env

Reporting bugs and contributing

Both contributing and bug reports are welcome. Please check out contributing guidelines.

Credits

Mislav Marohnić - the idea for the plugin came from his tmux-session script.

License

MIT

tmux-resurrect's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmux-resurrect's Issues

Possibility to restore via command line

I'm wondering if there is a way to restore automatically from command line. Similar to tmux kill-server except it would be something like tmux resurrect

Lets say on server start I would like to automatically restore the session so it is there for me the first time I log on. Is it possible or does one have to <ctrl>R after opening tmux?

Save program currently running in the pane

Saving currently running program should be easy.

Restoring is trickier because we don't want to restore everything (think - long running jobs, servers etc). There should be a conservative list of programs that should be automatically started, and the user should be able to enhance it.

List of programs that should be restored:

  • vim
  • man
  • less
  • more
  • emacs?
  • rails console
  • pry
  • rails server???

some command line arguments are not being saved

It all depends on how the new pane is started. I know that there has been changes made via #43 but, given the way I then to launch ssh/mosh connections, it fails.

I have functions set up to launch a new pane with either ssh or mosh like so:

function smosh () {
  tmux neww -n $1 "/usr/bin/mosh  $*"
}

function ss () {
  tmux neww -n $1 "/usr/bin/ssh  $*"
}

Now with the new update, the base command gets saved, it just mosh-client or ssh. If I create a new pane via tmux new-window and then start the same commands as above, saving the full command plus arguments work. My last file looks like:

pane    TeSt    1       :bash   0       :       0       :/home/don      1       bash    :
pane    TeSt    2       :loki   0       :       0       :/home/don      1       mosh-client     :
pane    TeSt    3       :loki   0       :       0       :/home/don      1       mosh-client     :mosh-client loki | 192.168.1.10 60004
pane    TeSt    4       :loki   0       :-      0       :/home/don      1       ssh     :
pane    TeSt    5       :bash   1       :*      0       :/home/don      1       ssh     :ssh loki
window  TeSt    1       0       :       6b22,273x88,0,0,13
window  TeSt    2       0       :       6b23,273x88,0,0,14
window  TeSt    3       0       :       6b24,273x88,0,0,15
window  TeSt    4       0       :-      6b25,273x88,0,0,16
window  TeSt    5       1       :*      6b26,273x88,0,0,17
state   TeSt

Where panes 2 & 4 are using my bash functions above, and panes 3 & 5 are using the new-window and then start the command method.

I have tracked the issue to the way the PID is passed to $HOME/.tmux/plugins/tmux-resurrect/save_command_strategies/ps.sh, but I am not sure where to go look to get it the correct PID of the pane.

Please let me know what other I can provide, or where I can go look to help fix this issue. This is a major road-block on my adoption of this fine plugin full time.

Thanks!

d

Problems with the first panel of the first window

This plugin is awesome, and everything works perfectly fine, except for the first panel of the first window.

When I save the session with ressurrect, execute tmux detach, execute tmux new -s work and then reload the environment using ressurrect, the first panel of the first window keeps the same state that my raw terminal had just after tmux was detached. All the other panels, on all the other windows work just fine.

My environment:

osx 10.9.3
terminal 2.4
tmux 1.9

Let me know if you need anything any more information about this issue.

tmux source-file ~/.tmux.conf returned 127

Hi, I tried to install this as a plugin using the TPM unfortunately that didn't work. I tried manually afterwards, cloned it and put it under plugins dir, I added the line in the instructions.

run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux

Then run tmux source-file ~/.tmux.conf but get this back:

'/Users/ilteris/.tmux/plugins/tmux-resurrect/resurrect.tmux' returned 127

currently,I couldn't make the plugin work for me. I am on tmux 1.9a. I would love to make this work.

You can check out my tmux.conf file here: https://github.com/ilteris/dotfiles/blob/master/tmux.conf

Thanks in advance.

Allow to restore local programs

I would like to be able to restore multiple local programs - starting with "./"

Currently there is two issues:
1 the "./" is stripped from the command
==> instead of running './my_program', it will run 'my_program' and display
my_program: command not found

2 To only start some local programs, I should be able to add to the tmux.conf
set -g @resurrect-processes './my_program'

Window names are no longer dynamic after restore

I started using tmux-resurrect recently, and I really like it, but I seem to have a problem with window names.

Before I started using tmux-resurrect, window names would be updated based what was running in them at the time. When working on a resurrected session, however, the names of the resurrected windows never change: If I run vim on one of them, the name is still bash. If I quit vim on one that was already called vim (because it was running vim when I saved the session), its name keeps being vim.

node-dev / restore functionality

Hey nice useful project here.

I noticed set -g @resurrect-processes '"~node-dev"' doesn't work, but i think set -g @resurrect-processes '"~node"' did restore, but restored only a blank node session, not my original node-dev index.js command.

I think node-dev actually calls node and the process runs as node.

What if tmux-restore detected whether a window had a process running, and you based restoring on the command that caused that program to run?

If I add node to my processes, i get a terminal that runs as if I had merely called node by itself, and it appears not to care what initially spawned the process.

This could be possible, right, by sniffing the history? I see the list of processes as a whitelist, interested by the currently running processes during a save. If they match, then run the same command again. Right?

Failed to resurrect first panel?

Firstly, thanks for your effort on this good plugin. I have tested several times, I found that the first panel I created always failed to resurrect. I have checked the saved file, I see the directory and vim file are all looks good. But the first panel always just use the default directory and do not resurrect my vim session, at the same time, other panels are all works well, do you have any idea? thanks.

Add a function to save/restore only a specific session

I would love to see a "per session" handling instead saving the whole server.

Here is the idea:
I have a teamocil config for the bigger projects, which are spawned in the morning. When the day goes on I add new windows/panes to log some stuff or edit a special file(s) in its own place. Day ends with additional mini sessions, which have no name and only some windows ... stuff. I thought to save a clean, good working state of a session so it is easily possible to restore a clean state of this session (aka project/task). At the end of the day you just kill the server with all the mess you created. At the next morning you can spawn your saved sessions one after the other when you need them. This makes manual crafting of session files obsolete and sessions are able to evolve easily. I hope you like the idea :-)

Command line prompt not ideal after a restore

This is how the command line prompt looks for some panes after a restore.
screen shot 2014-09-02 at 1 58 14 pm

After any key is pressed, the prompt is normalized to this
screen shot 2014-09-02 at 2 01 33 pm

Apart from how it looks there seems to be no other errors related to this.

Interestingly, this "garbled prompt" does not appear for all panes, only for some.
This needs some investigation as I'm not sure why it happens.

bash history save needs to account for remote sessions

I just completed my first bash history save. Unfortunately, in one pane I'm ssh'd into a remote session. The "history -w" command is echoed to the remote session.

Perhaps one way to easily determine if a user is connected to a remote session in a particular pane would be to look for a key or pattern in the user's bash prompt? The prompt should follow a consistent pattern on the local host, so when that prompt changes it could be deduced that the user has remote connection, therefore, don't try to save the history for that pane.

Another option would be to insert a key into the prompt and just look for that.

Not able to restore grunt

Should run grunt using "grunt development"

I'm using this setting in .tmux.conf: set -g @resurrect-processes ':all:'

This is the output in the console when resurrecting:

grunt ARCHFLAGS=-arch i386 -arch x86_64 Apple_PubSub_Socket_Render=/tmp/launch-Ou97Qf/Render
➜ pdm git:(master) ✗ grunt ARCHFLAGS=-arch i386 -arch x86_64 Apple_PubSub_Socket_Render=/tmp/launch-Ou97Qf/Render
Warning: Task "ARCHFLAGS=-arch" not found. Use --force to continue.

Command arguments are not saved/restored

As stated in #32 this should work. I run commands with arguments, but they not saved properly it seems. Test case: I ran tail -f README.md in the session "test", this is what was saved in 'last':

pane    0   0   :zsh    1   :*  0   :/home/hoschi   1   zsh :
pane    project-context-manager_second  0   :grunt  0   :-  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_second  1   :zsh    1   :*  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_vim 0   :vim    1   :*  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   vim :vim
pane    project-context-manager_vim 1   :git    0   :-  0   :/home/hoschi/repos/sweetp-code/services/project-context-manager    1   zsh :
pane    project-context-manager_vim 2   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/password-manager   1   vim :vim
pane    project-context-manager_vim 3   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/base-nodejs/lib    1   vim :vim
pane    project-context-manager_vim 4   :vim    0   :   0   :/home/hoschi/repos/sweetp-code/services/github-issues  1   vim :vim
pane    serien  0   :desktop    1   :*  0   :/home/hoschi   1   zsh :
pane    serien  0   :desktop    1   :*  1   :/home/hoschi   0   zsh :
pane    test    0   :git    1   :*  0   :/home/hoschi/repos/chrome-app-samples  1   tail    :tail
pane    tmux-conf   0   :vim    1   :*  0   :/home/hoschi   1   vim :vim
pane    tmux-conf   1   :vim    0   :-  0   :/home/hoschi   1   vim :vim
pane    tmux-conf   2   :man    0   :   0   :/usr/share/man 1   zsh :
pane    tmux-conf   3   :zsh    0   :   0   :/home/hoschi   1   zsh :
window  0   0   1   :*  d23d,151x78,0,0,0
window  project-context-manager_second  0   0   :-  d23e,151x78,0,0,1
window  project-context-manager_second  1   1   :*  d23f,151x78,0,0,2
window  project-context-manager_vim 0   1   :*  d240,151x78,0,0,3
window  project-context-manager_vim 1   0   :-  d241,151x78,0,0,4
window  project-context-manager_vim 2   0   :   d242,151x78,0,0,5
window  project-context-manager_vim 3   0   :   d243,151x78,0,0,6
window  project-context-manager_vim 4   0   :   d244,151x78,0,0,7
window  serien  0   1   :*  f619,151x78,0,0[151x48,0,0,8,151x29,0,49,9]
window  test    0   1   :*  694f,151x78,0,0,10
window  tmux-conf   0   1   :*  6950,151x78,0,0,11
window  tmux-conf   1   0   :-  6951,151x78,0,0,12
window  tmux-conf   2   0   :   6952,151x78,0,0,13
window  tmux-conf   3   0   :   6953,151x78,0,0,14
state   test    test

Only tail got saved, not the arguments:

pane    test    0   :git    1   :*  0   :/home/hoschi/repos/chrome-app-samples  1   tail    :tail

Here is my config:

# Activity monitoring
#setw -g monitor-activity on
#set -g visual-activity on

# Highlight active window
#set-window-option -g window-status-current-bg red

set -g default-terminal "screen-256color"

# utf8 is on
set -g utf8 on
set -g status-utf8 on

# address vim mode switching delay (http://superuser.com/a/252717/65504)
set -s escape-time 0

# tmux messages are displayed for 4 seconds
#set -g display-time 4000

# refresh 'status-left' and 'status-right' more often
#set -g status-interval 5

# Highlight active pane
#set-option -g pane-active-border-style bold
set-option -g pane-active-border-bg blue

# use powerline as status line
source '/home/hoschi/src/powerline/powerline/bindings/tmux/powerline.conf'

# create splits by | and -
unbind %
bind | split-window -h
bind - split-window -v

unbind p
# -n is for 'now prefix' !
bind-key -n F7 previous-window
bind-key a previous-window
bind-key -n F8 next-window
bind-key e next-window
bind-key C-b last-window

# renumber window so they have always continuing numbers
set -g renumber-windows on

# use vim motion keys while in copy mode
setw -g mode-keys vi

# use mouse!
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on

# scroll with mouse wheel in pane, not in terminals scrollbuffer
set -g terminal-overrides 'xterm*:smcup@:rmcup@'

# set history size
set -g history-limit 10000

##CLIPBOARD selection integration
##Requires prefix key before the command key
#Copy tmux paste buffer to CLIPBOARD
#
#
# attention: install xclip!
bind C-c run "tmux show-buffer | xclip -i -selection clipboard"
#Copy CLIPBOARD to tmux paste buffer and paste tmux paste buffer
bind C-v run "tmux set-buffer -- \"$(xclip -o -selection clipboard)\"; tmux paste-buffer"



# List of plugins
# Supports `github_username/repo` or full git URLs
#
# https://github.com/tmux-plugins/tmux-resurrect
# https://github.com/tmux-plugins/tmux-sessionist
set -g @tpm_plugins "              \
  tmux-plugins/tpm                 \
  tmux-plugins/tmux-resurrect   \
  tmux-plugins/tmux-sessionist     \
"
# Other examples:
# github_username/plugin_name    \
# [email protected]/user/plugin     \
# [email protected]/user/plugin  \

# initializes TMUX plugin manager
run-shell ~/.tmux/plugins/tpm/tpm

# https://github.com/tmux-plugins/tmux-resurrect
set -g @resurrect-processes 'ssh "git log" grunt-wrapper tail'

I'm on Arch Linux, tmux version is 1.9a

issues with keybindings

Not sure what im doing wrong, but hitting prefix+alt-s does nothing for me :(

Really excited about this project though :)

history command should be pruned from bash save history

When saving bash history, the "history" command itself should be pruned from the saved history file. That command isn't really part of the user's history, rather it is a side-effect of saving the bash history via the tmux script.

Suggestion for refactoring of scripts/save.sh and scripts/restore.sh.

First off, this is an absolutely awesome project and I'm already using it to great success.

While looking through the code I noticed that scripts/save.sh is writing a tab-delimited file of all of the session, window, and pane settings. Later on, scripts/restore.sh reads and parses that file, executing TMUX commands as it goes.

I think it would be much simpler to have the file that scripts/save.sh writes be valid, parseable tmux commands. This would help with reading and debugging of the saved session files and would make scripts/restore.sh much simpler.

I'm happy to put up a PR to refactor this, but I wanted to get your thoughts first.

key binding disappears when setting @resurrect-restore

When I attempt to set the resurrect-restore variable to 'C-r', the binding seems to disappear. Here are the steps to reproduce this:

  • Install tmux-resurrect through tpm.
  • When I list keys, I get:
tmux list-keys | grep 'resurrect'
bind-key        M-r run-shell ~/.tmux/plugins/tmux-resurrect/scripts/restore.sh
bind-key        M-s run-shell ~/.tmux/plugins/tmux-resurrect/scripts/save.sh
  • Put set -g @resurrect-restore 'C-r' in ~/.tmux.conf, as mentioned by @bruno in #29.
  • Restart tmux server
  • Now when I list keys, the restore binding is gone:
tmux list-keys | grep 'resurrect'
bind-key        M-s run-shell ~/.tmux/plugins/tmux-resurrect/scripts/save.sh

Any ideas why the binding disappears? I'm also running on OS X if that information helps.

Proposal for auto-save

Would it be possible to set up auto save for tmux-resurrect.
Just two extra configuration settings: enable or disable autosave and autosave interval.

Not able to restore karma when adding it to the @resurrect-processes

This problem happens when I have this in my .tmux.conf file: set -g @resurrect-processes 'karma'

The command I run is: karma start karma-unit.conf

When resurrecting, it says: tmux restore complete. But nothing really happened. It didn't restored karma and there are no errors in the console.

Restore session gives ouputs 'no results'

So I just saved a session and tmux outputed session saved as it was suposed to.
Now I've just created a new session and when I hit ctrl-a ctrl-r I get a message saying 'No results!'

Any idea why?

You should add node.js

I run a couple of node.js clients via tmux. I guess it's not a rare case.

Open a GitHub issue if you think some other program should be on the default list.

Done!

pane directories not restored

Hi

I am starting to use this great plugin. I have created a session, but when I restore it, my panes are not in the dirs I left them at. I didn't find anything in the readme about this, do I need to do something special?

thanks

Pane layout not saved if one pane was maximized

How to reproduce:
Split panehorizontally (prefix + ")
Maximize one pane (prefix + z)
Save session (prefix + alt s)
Restart tmux
Load session (prefix + alt r)
Unmaximize pane (prefix + z)

Result:
Instead of having a horizontal split you now have a vertical split.

If you have multiple panes (in any layout) then all of them are vertically split after loading the session.

Here are two examples of four panes in the ~/.tmux/resurrect/last:

window»·0»0»0»: »·65e6,211x63,0,0{105x63,0,0,0,105x63,106,0[105x30,106,0,1,105x32,106,31{52x32,106,31,2,52x32,159,31,3}]}
window»·0»1»0»:Z»·5de1,211x63,0,0,12

As can be seen the first window has 4 panes which have a proper layout. The second window has a maximized window, but there is no information saved about the layot of the rest.

Preserve bash history

Please consider saving Bash history for each pane. This can be done relatively simply (on Bash side) by using following commands:

# save history
history -w $HISTORY_FILE
# restore
history -r $HISTORY_FILE

How to send these commands to each pane is a trickier question, but I believe tmux's send-keys functionality can achieve this - at least when no program is running in given pane.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.