I restore common setups for my project with something equivalent to this:

tmux new-session "tmux source-file $setup_file"

I would normally assume that starting a new session and then sourcing commands from $setup_file would be equivalent to manually executing those tmux commands in a new shell, but it's not! The difference is that when sourcing, no shell seems to be created in window 0, so when I execute neww this creates a window 1, but window 0 is missing when everything has been setup. To hack around this I execute split-window, but I do not understand why I need to do this. Clues?


# window 0 - cli
rename-window 'cli';
split-window # not sure why this is needed to get a shell. Otherwise there is no window 0!

# window 1 - main window in the left pane and 3 minor windows in the right pane
rename-window 'tools'
send-keys 'nvim' C-m  # editor
split-window -h -p 40 # build window (webpack, etc)
split-window -v -p 80             # cli
split-window -v -p 50             # test runner?
select-pane -L; # select the left pane; nvim

1 Answer 1


but window 0 is missing when everything has been setup

Without the questionable split-window, the code that runs in only pane in window 0 is tmux source-file $setup_file (with $setup_file already expanded by the original shell). When everything is set up this command terminates, so the only pane terminates, so the window terminates.

It would be different with

tmux new-session "tmux source-file '$setup_file'; '$SHELL'"

Note this command is quoted "better" than your original command, but still not properly quoted. In Bash proper quoting can be achieved thanks to ${var@Q}:

tmux new-session "tmux source-file ${setup_file@Q}; ${SHELL@Q}"
  • That makes total sense. Thanks.
    – oligofren
    Commented Apr 14, 2021 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .