tmux-continuum icon indicating copy to clipboard operation
tmux-continuum copied to clipboard

Autosave not working

Open gerases opened this issue 7 years ago • 19 comments

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?

gerases avatar Apr 28 '18 01:04 gerases

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.

bruno- avatar Apr 28 '18 12:04 bruno-

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'

dylan-chong avatar Jun 28 '18 00:06 dylan-chong

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.

SCdF avatar Feb 05 '19 11:02 SCdF

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- avatar Sep 03 '19 07:09 kugel-

Without the setting continuum_status.sh gives this:

./scripts/continuum_status.sh: line 12: [: -gt: unary operator expected
off

kugel- avatar Sep 03 '19 07:09 kugel-

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.

atsepkov-zaius avatar Nov 12 '19 18:11 atsepkov-zaius

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.

jjose3 avatar Nov 22 '19 00:11 jjose3

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

jandamm avatar Mar 24 '20 10:03 jandamm

:O Ill give it a go!

dylan-chong avatar Mar 24 '20 19:03 dylan-chong

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.

jandamm avatar Mar 24 '20 19:03 jandamm

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

dylan-chong avatar Mar 24 '20 19:03 dylan-chong

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)

jandamm avatar Mar 24 '20 20:03 jandamm

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

dylan-chong avatar Mar 25 '20 00:03 dylan-chong

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.

rhazegh avatar May 25 '20 21:05 rhazegh

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.

wsh3776 avatar Aug 26 '20 15:08 wsh3776

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.

studgeek avatar Sep 10 '21 19:09 studgeek

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

nyngwang avatar Dec 13 '21 10:12 nyngwang

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.

sukrosono avatar Mar 08 '22 14:03 sukrosono

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

bliuchak avatar Mar 13 '23 16:03 bliuchak