Search code examples
shellcommand-linetmux

Prevent tmux from exiting when script finishes


I'd like to prevent tmux from exiting automatically when the script finishes. For example, I have a command something like this(below), this does run a server for an app, but sometimes this unexpectedly exits with an error. When that happens, I'm unable to check what was wrong with the code, command.

tmux new-session -d -s "visited" 'bash -ic "visited --server"';

Following one is a simplified command of what I'd like to do.

tmux new-session -d -s "pwd" 'bash -c pwd' # but actually I need to load .bashrc
tmux a -t pwd # this should attach to the shell, but in my environment this does show "can't find session pwd" since the shell is already exited

I read a github issue and tried to add set exit-empty off to ~/.tmux.conf and restart the server tmux kill-server and re-tried the above, but seemed it doesn't work.


Solution

  • Just let tmux create a normal session and inject the keystrokes:

    tmux new-session -d -s pwd
    tmux send-keys pwd C-m
    tmux a -t pwd