evnp / tmex

tmux-execute – a lightweight tmux command & layout composer
MIT License
87 stars 5 forks source link

Splits with no processes running close automatically when I close the terminal #10

Open marcelarie opened 4 months ago

marcelarie commented 4 months ago

I suppose this is something related to tmux, but I create the splits with tmex, and I wanted to know what can I do to keep the splits when I close a terminal.

This is the command that I use to create the sessions:

tmex "$SESSION" --layout="2{41}" "cd $REPO_NAME; clear; $EDITOR" "cd $REPO_NAME; clear"

The one that always closes is the bottom split:

"cd $REPO_NAME; clear"

Thanks in advance.

evnp commented 4 months ago

Hi @marcelarie, thanks for reporting this. There are a couple things that could be going wrong here – the intended default behavior is that a pane running "cd $REPO_NAME; clear" would remain open with a blank interactable shell. I'm observing this behavior, which makes me think this is due to some difference in tmux configuration.

Would you mind sharing your .tmux.conf or other tmux configuration here? In particular I'm wondering if

It would also be useful to know what tmex outputs for you when -p flag is passed. Here's what it says for me (nx being a test repo):

$ SESSION=nx-repo-session; REPO_NAME=nx; tmex $SESSION -p --layout="2{41}" "cd $REPO_NAME; clear; $EDITOR" "cd $REPO_NAME; clear"

new-session -s nx-repo-session ; send-keys "cd nx; clear; nvim" Enter ; split-window -v -l20% ; send-keys "cd nx; clear" Enter

I think the most important thing here is that tmex is passing commands to tmux with send-keys, instead of passing them for direct execution. This is meant to execute the commands within shells in tmux panes, instead of executing them directly (which would cause the pane to die afterward).

This tmux thread may also be useful – describes a similar issue and mentions shells and remain-on-exit: https://github.com/tmux/tmux/issues/2410

marcelarie commented 4 months ago

Hi @evnp, thanks for checking!

new-session -s dev-portal-test ; send-keys "cd dev-portal; clear; nvim" Enter ; split-window -v -l20% ; send-keys "cd dev-portal; clear" Enter


This is my tmux.conf:
```shell
bind-key C-Space send-prefix
set -sg escape-time 0
set-option -g focus-events on
set-option -g base-index 1
set-option -g history-limit 50000
set-option -g prefix C-Space
setw -g aggressive-resize on
unbind-key C-b

# Enable custom pane navigation and resizing
set-window-option -g mode-keys vi
bind -r h select-pane -L
bind -r j select-pane -D
bind -r k select-pane -U
bind -r l select-pane -R
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# set-option -g default-shell /opt/homebrew/bin/nu
set-option -g default-shell /opt/homebrew/bin/fish

set-option -g detach-on-destroy off

set -g set-clipboard off
set -g message-command-style "fg=colour154,bg=colour0"
set -g message-style "fg=colour154,bg=colour0"
set -g mouse on
set -g status "on"

bind v split-window -h -c '#{pane_current_path}' 'fish'
bind s split-window -v -c '#{pane_current_path}' 'fish'
bind V split-window -f -h -c '#{pane_current_path}' 'fish'
bind S split-window -f -v -c '#{pane_current_path}' 'fish'
bind n split-window -f -v -c '#{pane_current_path}' 'fish'
bind K kill-session

bind-key c split-window -b -l 25 -c '#{pane_current_path}' 'fish'

set -ga terminal-overrides ",xterm-256color:Tc"
set-option -g renumber-windows on

bind f display-popup -E "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t"

set -g @plugin 'niksingh710/minimal-tmux-status'

set -g @minimal-tmux-bg "#698DDA"
set -g @minimal-tmux-justify "centre"
set -g @minimal-tmux-indicator-str "  tmux  "
set -g @minimal-tmux-indicator true
set -g @minimal-tmux-status "bottom"

# Enables or disables the left and right status bar
set -g @minimal-tmux-right true
set -g @minimal-tmux-left true

# expanded icon (fullscreen icon)
set -g @minimal-tmux-expanded-icon " 󰊓 "

# on all tabs (default is false)
# false will make it visible for the current tab only
set -g @minimal-tmux-show-expanded-icons-for-all-tabs true

# To add or remove extra text in status bar
set -g @minimal-tmux-status-right-extra ""
set -g @minimal-tmux-status-left-extra ""

# Not recommended to change these values
set -g @minimal-tmux-status-right "#S"
set -g @minimal-tmux-status-left "#I:#P"

run '~/.tmux/plugins/tpm/tpm'
evnp commented 4 months ago

Thanks for all that @marcelarie. I've set up fish and your tmux config on my machine in hopes of a repro, no luck there unfortunately. Screenshot below [1] of what I end up with, which I assume is something like what you're expecting but it would be good to make sure.

I think remain-on-exit is a red herring.. I've tried setting it explicitly to "off" with your config and in the tmex script itself, in both cases the pane remains open.

I'm wondering if we could pare down your example which would maybe help isolate the problem. Can you try running this simpler command? I'd like to know if the pane sticks around or still closes immediately (my result is screenshot [2]). I'd also be curious to know whether the pane survives when running the same commands but without "; clear", and also without "cd $REPO_NAME; clear" (just pass an empty string for the second command).

SESSION=dev-portal-test; REPO_NAME=dev-portal; tmex $SESSION "cd $REPO_NAME; clear"
SESSION=dev-portal-test; REPO_NAME=dev-portal; tmex $SESSION "cd $REPO_NAME"
SESSION=dev-portal-test; REPO_NAME=dev-portal; tmex $SESSION ""

I should have asked this earlier – would also be good to know what versions of tmux and tmex you're running:

$ tmux -V
tmux 3.4
$ tmex -V
tmex 2.0.0-rc.5

[1]

Screen Shot 2024-05-13 at 9 12 54 AM

[2]

Screen Shot 2024-05-13 at 9 13 40 AM
marcelarie commented 4 months ago

@evnp, thanks for your input. I am currently busy, but I'll find time to respond soon.