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

New window is always added when auto restoring tmux environment #50

Open while0pass opened 6 years ago

while0pass commented 6 years ago

Every time I start tmux and it restores the environment, a new additional session with a blank window is added. There is no such a problem if I restore my sessions with tmux-ressurect manually.

dylan-chong commented 6 years ago

I find this annoying too. I think there should be an option to remove the session that appears when tmux is started up

AdrienLemaire commented 4 years ago

As a temporary hack, I added tmux kill-session -t 0 before the main() stop_spinner call in .tmux/plugins/tmux-resurrect/scripts/restore.sh:369, since all my sessions are named and the unwanted one is always called 0

aguytech commented 3 years ago

Hi, Here is a possible solution to this issue : pull-request https://github.com/tmux-plugins/tmux-continuum/pull/83

The problem to clean this added session at each restart is that when you are in the process of daemon creation (calling tmux-continuum), you can't kill session. So i had to externalize the call of tmux daemon in the script to have possibility to kill session after the daemon is started.

dylan-chong commented 3 years ago

For some reason a new window is no longer created for me now

aguytech commented 3 years ago

@dylan-chong Which OS and tmux version do you use ?

aguytech commented 3 years ago

For me: I tried few days ago with a fresh install of tmux-resurrect & tmux-continuum from github my tmux version are 3.1_c-1 Os: manjaro

Here is my problem:

$ tmux ls
0: 1 windows (created Sun Nov 29 01:04:07 2020)
$ systemctl restart --user tmux.service
$ systemctl restart --user tmux.service
$ systemctl restart --user tmux.service
$ tmux ls
0: 1 windows (created Sun Nov 29 01:14:50 2020)
1: 1 windows (created Sun Nov 29 01:14:50 2020)
2: 1 windows (created Sun Nov 29 01:14:50 2020)
3: 1 windows (created Sun Nov 29 01:14:51 2020)

Something seems to be wrong?

Here is my file .tmux.conf without binds:

# prefix key
set-option -g prefix C-q
# time allowed to repeat key following prefix key
set-option -g repeat-time 500
# set history to 5000
set-option -g history-limit 5000

# tmux-continuum
set -g @continuum-boot 'on'
set -g @continuum-restore 'on'

####  plugins

# resurect plugin
run-shell ~/.tmux/plugins/tmux-resurrect/resurrect.tmux
run-shell ~/.tmux/plugins/tmux-continuum/continuum.tmux
dylan-chong commented 3 years ago

@dylan-chong Which OS and tmux version do you use ?

> tmux -V
tmux 3.1c

Mac os 10.14.6

My tmux conf is here https://github.com/dylan-chong/dotfiles/commit/0c9a4840e73f9c33b1189bf8a5a9361b13874612

aguytech commented 3 years ago

Mac os 10.14.6

Ok the problem seems to come from systemd (linux)

dylan-chong commented 3 years ago

Nevermind. the problem is back for me :( I swear it was fine in the last few weeks

austinbutler commented 3 years ago

Yeah this happens for me on MacOS.

bruno- commented 3 years ago

Hey guys, the original problem with session 0 being always present is solved via https://github.com/tmux-plugins/tmux-resurrect/commit/5f5f9d8fd5ff9769e5ef08d64a430ee7ab525dc7

About the new problem "session with an increasing session number appears after restart":

ioogithub commented 2 years ago

What is the current status of this bug?

I am a new user to tmux and tmux-continuum so I am confused at what I was seeing. I expected that I this plugin will being me back to my saved session when I had the following settings:

set -g @continuum-boot 'on' set -g @continuum-restore 'on'

Instead I always got a new session with a new higher session number that I have to manually get rid of. This actually creates more work than not using the feature at all.

Is this the expected behavior or is this still the bug. From a (confused) new user perspective I wanted the plugin to restore my last saved session. When I launch tmux I wanted it to bring me back to this session. When I started the computer I wanted tmux to return me to the last saved session but it doesn't do this at all. This bug report was opened almost 3 years ago... is this feature still currently broken? Are there any easy work arounds?

UbiquitousPhoton commented 2 years ago

There is one easy workaround: set @continuum-systemd-start-cmd = 'start-server'

It defaults to new-session -d, which creates the new session each time, then restores the others. I am not entirely sure why.

Note that setting this variable is not enough, you need to force regeneration of your systemd unit file - so either delete ~/.config/systemd/user/tmux.service and the script should recreate it, or just hand edit the aforementioned file manually.

ioogithub commented 2 years ago

There is one easy workaround: set @continuum-systemd-start-cmd = 'start-server'

What does between the " " is this where you place the command you want to start or is this command complete as it is? I tried this but it did not work. When I enable this command and reload tmux I still get the default. I saw the documentation mentioned this as well but I have tried several different attempts and never got it working.

ioogithub commented 2 years ago

the original problem with session 0 being always present is solved via tmux-plugins/tmux-resurrect@5f5f9d8

Has anyone else confirmed this change is working? I am running tmux 3.2a and tmux-restore version 4.0 (as per the CHANGELOG.mg file in my ~.tmux/plugins/tmux-resurrect/ folder) but I get a new 0 session after every restore. I have tested this extensively tonight.

I believe this 0 session is also causing other issues with restoring.

Example after a restore:

user@server:~$ tmux list-session
0: 1 windows (created Sun Aug 28 22:27:48 2022)
test: 7 windows (created Sun Aug 28 22:27:46 2022) (attached)
kranich commented 5 months ago

When I installed tmux-continuum via tpm, my stored sessions were restored and I did not get any extra session. When I called tmux-continuum directly from tmux.conf with

run-shell <path to continuum.tmux>

I always ended up with my stored sessions being restored and an extra session.

I believe that the cause for that is the order of execution. In the former case, tmux would source tmux.conf, then create a new session, then tpm would invoke tmux-continuum and it would call tmux-resurrect to correctly restore my stored sessions replacing the existing session. In the latter case, tmux would source tmux.conf, calling tmux-continuum and waiting for it, then tmux-continuum would call tmux-resurrect to restore the stored sessions, and only then tmux would finish its initialization by creating a new session.

I could fix that behaviour by running continuum.tmux in the background at the bottom of tmux.conf with

run-shell -b <path to continuum.tmux>

i.e. by adding the -b flag to run-shell. Like that, tmux does not wait for continuum.tmux and instead finishes its initialization and creates a new session before tmux-continuum calls tmux-resurrect to restore the stored sessions.