tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.35k stars 423 forks source link

Sessions not correctly persisted when using zsh #271

Closed ghost closed 6 years ago

ghost commented 6 years ago

Just discovered this amazing plugin and the first thing I must say: it is amazing to be able to save sessions for later, you're all doing a great job :1st_place_medal:. While saving and restoring the layouts was easy, I haven't been able to "resurrect" running programs. Not even talking about custom programs, but the ones that should be "resurrected" by default (ie: htop).

So I run tmux, create a split pane, run htop and then save with prefix C-s.

Looking at my ~/.tmux/resurrect/last I can see the following:

pane    0   0   :htop   1   :*  0   :/home/dsiguero 0   zsh :-zsh
pane    0   0   :htop   1   :*  1   :/home/dsiguero 1   htop    :-zsh
htop
window  0   0   1   :*  1225,239x60,0,0[239x30,0,0,0,239x29,0,31,1]
state   0   

As far as I've seen (mostly from other people's last files on this repo):

When manually modifying the last file and changing it to something like the following, it re-runs htop successfully, after the session is restored:

pane    0   0   :htop   1   :*  0   :/home/dsiguero 0   zsh 
pane    0   0   :htop   1   :*  1   :/home/dsiguero 1   zsh :htop
window  0   0   1   :*  1225,239x60,0,0[239x30,0,0,0,239x29,0,31,1]
state   0   
############
# .tmux.conf #
############

# Set shell
set-option -g default-shell $SHELL

# Enable mouse control
set -g mouse on 

# Window status
# set -g window-status-format " #I:#W#F "
# set -g window-status-current-format " #I:#W#F "

# Current window status
# set -g window-status-current-bg colour24
# set -g window-status-current-fg colour232

# Window with activity status
# set -g window-status-activity-bg colour31  # fg and bg are flipped here due to
# set -g window-status-activity-fg colour233 # a bug in tmux

# Window separator
# set -g window-status-separator ""

# Window status alignment
# set -g status-justify centre

# Pane border
# set -g pane-border-bg default
# set -g pane-border-fg colour238

# Active pane border
# set -g pane-active-border-bg default
# set -g pane-active-border-fg colour24

# Pane number indicator
# set -g display-panes-colour colour233
# set -g display-panes-active-colour colour245

# Clock mode
# set -g clock-mode-colour colour24
# set -g clock-mode-style 24

# Message
# set -g message-bg colour24
# set -g message-fg black

# Command message
# set -g message-command-bg colour233
# set -g message-command-fg black

# Mode
# set -g mode-bg colour24
# set -g mode-fg colour231

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

# Session saving
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-capture-pane-contents 'on'

# Themepack and theme
set -g @plugin 'arcticicestudio/nord-tmux'

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

Other info:

Terminal emulator: termite Shell: zsh tmux -V: 2.7

Any ideas about what might be happening here?

Thank you! :)

bruno- commented 6 years ago

Hey,

I think your hunch is right. The program should be saved as :htop, not as :-zsh htop.

I think this would happen if you are for some reason running zsh inside another shell as a subprocess? I'm not sure if this line set-option -g default-shell $SHELL could be related?

Try checking your zsh shell's parent process is tmux process.

ghost commented 6 years ago

Thanks for your comment @bruno- :)

I added that line because this wasn't working and thought it could help. After removing that line and checking $$ and $PPID from a regular terminal and from tmux, this is what I've got:

Before launching tmux:

$ ps -aux | grep $$
# /bin/zsh
$ ps -aux | grep $PPID
# termite

From tmux:

$ ps -aux | grep $$
# -zsh 
$ ps -aux | grep $PPID
# tmux

I think it's weird how $$ changes from /bin/zsh to -zsh (including the dash, that same dash I'm seeing on the last files from resurrect) but I'm still clueless :(

ghost commented 6 years ago

I am now starting tmux as a user service and $$ seems to be consistent: /bin/zsh. However, when I save the session it still has shell and process inverted :/

pane   dsiguero    0       :htop   1       :*      0       :/home/dsiguero     0       zsh     :/bin/zsh
pane   dsiguero    0       :htop   1       :*      1       :/home/dsiguero     1       htop    :/bin/zsh
ghost commented 6 years ago

Looks like this is the same issue than https://github.com/tmux-plugins/tmux-resurrect/issues/215. I modified save_command_strategies/ps.sh to reflect the change from https://github.com/tmux-plugins/tmux-resurrect/pull/216 and it works. The saved sessions now look right (I believe):

pane    dsiguero    0   :htop   1   :*  0   :/home/dsiguero 0   zsh :
pane    dsiguero    0   :htop   1   :*  1   :/home/dsiguero 1   htop    :htop
bruno- commented 6 years ago

Thanks for the investigation. It turns out we can use the change proposed in #216 for all operating systems so I just did that via 9dc3f8c639cb8b1d868002a037b7edbf39f3dd12

Can you update the plugin from latest master and let me know if this fixes the problem for you? If yea, can you please close the issue. Thanks.

ghost commented 6 years ago

Yes, it is working now. Thank you!