tmux-plugins / tmux-continuum

Continuous saving of tmux environment. Automatic restore when tmux is started. Automatic tmux start when computer is turned on.
MIT License
3.29k stars 149 forks source link

Autosave not working #48

Open gerases opened 6 years ago

gerases commented 6 years ago

Autosave is not working and I've narrowed it down to this piece of code:

# Advanced edge case handling: start auto-saving only if this is the
# only tmux server. We don't want saved files from more environments to
# overwrite each other.
if ! another_tmux_server_running; then
  # give user a chance to restore previously saved session
  delay_saving_environment_on_first_plugin_load
  add_resurrect_save_interpolation
fi

The problem is that I share my work environment with several co-workers. So, in total we may have > 3 tmux processes. This function grabs all of them:

all_tmux_processes() {
  # ignores `tmux source-file .tmux.conf` command used to reload tmux.conf
  ps -Ao "command pid" |
    \grep "^tmux" |
    \grep -v "^tmux source"
}

Long story short, it seems that add_resurrect_save_interpolation is never called because continuum thinks there are more than one TMUX servers running. Should it not consider only the running user's processes?

bruno- commented 6 years ago

This, as you described it, works as designed. Honestly, this plugin was not written to handle your use case (multiple tmux server processes).

Should it not consider only the running user's processes?

Yes, I think this is a good suggestion. I'd be open to accepting a PR for this.

dylan-chong commented 6 years ago

I also have problems with autosave not working even though I only have one tmux process

set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-strategy-nvim 'session'
# Continuum
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @continuum-restore 'on'
# Ressurect vim sessions
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-strategy-nvim 'session'
# Resurrect other programs
set -g @resurrect-processes '~server_osx.py'
# Change key bindings
set -g @resurrect-save 'S'
set -g @resurrect-restore 'R'
SCdF commented 5 years ago

So I don't have multiple tmux servers running, but I am attached in multiple places:

$ ps -ef | grep tmux
  501 15381     1   0 Sun10am ??         9:03.52 tmux
  501 22576 22450   0 11:41am ttys000    0:00.01 tmux a
  501 24276 16899   0 11:43am ttys007    0:00.00 grep tmux
  501 23241 23119   0 11:42am ttys020    0:00.01 tmux a
  501 23508 23386   0 11:42am ttys021    0:00.01 tmux a

This causes issues with automated recordings. Manually saving them works fine, and occasionally the save works, but generally it's that the symlink isn't pointing where it should.

kugel- commented 5 years ago

I also this problem. It seems that the default interval of 15 min isn't applied. If I manually set set -g @continuum-save-interval '15' it /seems/ to work.

I judge by the output of scripts/continuum_status.sh which I put into my powerline configuration.

kugel- commented 5 years ago

Without the setting continuum_status.sh gives this:

./scripts/continuum_status.sh: line 12: [: -gt: unary operator expected
off
atsepkov-zaius commented 5 years ago

I had the same issue, contrary to what the README says without explicitly specifying the save interval in .tmux.conf, auto-saving doesn't work.

jjose3 commented 4 years ago

I had a problem with autosave though I'm using only one tmux server. I use tmux attach to attach the sessions. This gets counted in for all_tmux_processes. So, I added a grep -v for tmux attach in helpers.sh

all_tmux_processes() {
  # ignores `tmux source-file .tmux.conf` command used to reload tmux.conf
  ps -Ao "command pid" |
    \grep "^tmux" |
    \grep -v "^tmux source" |
    \grep -v "^tmux attach"
}

It works now.

jandamm commented 4 years ago

Not sure what exactly caused it but for me the culprit was https://github.com/jimeh/tmux-themepack. When sourcing my plugins with tpm I had to make sure to add the themepack before continuum.

Before (not working):

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

set -g @plugin 'jimeh/tmux-themepack'

After (working):

set -g @plugin 'jimeh/tmux-themepack'

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

Maybe it helps someone else :)

dylan-chong commented 4 years ago

:O Ill give it a go!

jandamm commented 4 years ago

Would make sense as the auto save command gets written into status-right. So everything that sets status-right would have to be loaded beforehand.

At least if I got right from reading the code. In my opinion this should be stated in the readme (if correct).

EDIT: Just tested it by echoing from ./scripts/continuum_save.sh main(). The script is the first segment of the right status. So every modification of status-right has to be done before tpm sources continuum.

dylan-chong commented 4 years ago

That's annoying. I manually override status right so that it only shows the information that I want to show :|. I have to run these overrides after run '~/.tmux/plugins/tpm/tpm' otherwise they won't get applied

jandamm commented 4 years ago

The added script doesn't print anything so there isn't anything added to your status-right visually. It just uses the refresh of the status line to run the save script.

If you have to modify status-right after tpm and want to use auto save, try adding this to your status-right: #(~/.tmux/plugins/tmux-continuum/scripts/continuum_save.sh)

dylan-chong commented 4 years ago

Holy crap you're right it is fixed for me now. Thank you so much for investigating this!

rhazegh commented 4 years ago

If you are using "Oh My Tmux" (https://github.com/gpakosz/.tmux):

Open .tmux.conf and find the following line:

#   status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')

Add these two lines after the above-mentioned line:

#   continuum_auto_save='#(~/.tmux/plugins/tmux-continuum/scripts/continuum_save.sh)'
#   status_right="$status_right$continuum_auto_save"

Save .tmux.conf and reload tmux configuration by <prefix> r inside a tmux session. Auto save should work now.

wsh3776 commented 4 years ago

If you are using "Oh My Tmux" (https://github.com/gpakosz/.tmux):

Open .tmux.conf and find the following line:

#   status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')

Add these two lines after the above-mentioned line:

#   continuum_auto_save='#(~/.tmux/plugins/tmux-continuum/scripts/continuum_save.sh)'
#   status_right="$status_right$continuum_auto_save"

Save .tmux.conf and reload tmux configuration by <prefix> r inside a tmux session. Auto save should work now.

👍 👍 👍 Thank you so much for solving the oh-my-tmux issue! It works for me.

studgeek commented 3 years ago

FYI, I added a minor pull request that makes continuum's dependency on status-right clearer in the README - https://github.com/tmux-plugins/tmux-continuum/pull/98.

I also created issue https://github.com/tmux-plugins/tmux-continuum/issues/99 to look for some hook other than status-right. I'm not sure if tmux has one, but would be nice if continuum didn't depend on status-right. I personally don't have the status bar on.

nyngwang commented 2 years ago

I have no problem with this. Why not just set -g status-right 'Continuum status: #{continuum_status}'?

sukrosono commented 2 years ago

I am half giving up on this, would you @nyngwang post what it looks like the continuum status on tmux bar, please? I always have a tmux error with no server running after reboot.

bliuchak commented 1 year ago

Just in case sharing my working config. With this config there is autosave every 1m and fully working "Continuum status" that shows "1" at status-right.

set -g default-terminal "xterm-256color"
set -g default-command zsh

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

set -g @continuum-restore 'on'
set -g @continuum-save-interval '1'
set -g status-right 'Continuum status: #{continuum_status}'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

Maybe it can be useful to someone :)