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.24k stars 149 forks source link

Find way to run automatically without depending on status bar and status-right #99

Open studgeek opened 3 years ago

studgeek commented 3 years ago

It would be nice if continuum didn't depend on tmux status bar being present and needing to modifying status-right.

I'm not sure if there is another hook in tmux to run something regularly though.

studgeek commented 3 years ago

I if tmux doesn't have a hook another option would be to add the continuum_save.sh to bash rather than tmux (e.g. PROMPT_COMMAND).

studgeek commented 3 years ago

Using bash would allow saving each history from inside each bash session also, which might get rid of https://github.com/tmux-plugins/tmux-resurrect/issues/288.

davehouser1 commented 2 years ago

Has anyone found a solution for this or is it just not supported? @studgeek mentioned "_add the continuumsave.sh to bash rather than tmux" but I am not sure what that means.

studgeek commented 2 years ago

I haven't tried it yet, but theory a continuum call could be added to bash's prompt commands to save the history on each prompt. That would require updating bashrc or something though.

adrianlzt commented 2 years ago

Workaround using a systemd timer:

# /home/adrian/.config/systemd/user/tmux-save.service
[Unit]
Description=Save tmux sessions
OnFailure=error@%n.service

[Service]
Type=oneshot
ExecStart=/bin/bash /home/adrian/.tmux/plugins/tmux-resurrect/scripts/save.sh
# /home/adrian/.config/systemd/user/tmux-save.timer
[Unit]
Description=Run each ten minutes

[Timer]
OnCalendar=*:0/10

[Install]
WantedBy=timers.target
theSafdarAwan commented 2 years ago

hey i got this cool hack if you are using any one the window manajers like i3 dwm or bspwm then you can start your terminal like alcritty or kitty and by adding the option /bin/alacritty -e tmux new then it will pick up the autostart session and will restore it to the last session.

Diablo-D3 commented 1 year ago

So, I'm doing this, and it seems to be working:

In .tmux.conf:

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

set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-restore 'on'
# (whatever resurrect and continuum options you want)

run ~/.tmux/plugins/tmux-continuum/scripts/continuum_restore.sh

In .bashrc:

precmd() {
  if [ -n "$TMUX" ]; then
    eval "$(tmux show-environment -s)"
    eval "$($HOME/.tmux/plugins/tmux-continuum/scripts/continuum_save.sh)"
  fi

  history -a
}

PROMPT_COMMAND=precmd

It seems to correctly save and restore.