top
runs until you quit. ls
exits after it prints the contents of the current directory. This causes the window in which ls
runs to close.
setw -t servers remain-on-exit on
should keep the the window named 'servers' from closing after its command exits, but it is complicated by the fact that the window does not exist before the new-session
command is run, and after new-session
returns, it may be too late to run the setw
command (although you can try).
Instead, create a new session in which the default is for a window to remain after its command exists:
new -A -s 'main' -n 'servers' 'ls' # troubled line
set -t main set-remain-on-exit on
neww -n 'servers' ls
Based on your last comment, ignore the above, and replace your new
command with
new -A -s 'main' -n 'servers'
send-keys -t servers.0 ls Enter
This creates a regular window, whose command is a regular shell, but then simulates typing the ls
command at the first shell prompt to provide you with the list of files in that directory. After ls
completes, you are back in the shell, and the pane will continue to exist until the shell itself completes.