Why does ‘tmux’ create new windows as login shells by default?
When you start a new session in tmux
or create a new window inside a running session, its default behaviour is to run a shell (ex.: bash
) as a login shell.
I understand that a login shell is intended to execute a routine of configurations and procedures that are of interest just when you are logging in a system. But in the majority of the cases (with the exception that you can use tmux
as a login shell) it’s not the true intent of the user to do this when he just wants to open a new window.
So what is the rationale for making this the default behaviour of tmux
?
The only thing the documentation says about the matter:
default-command shell-command Set the command used for new windows (if not specified when the window is created) to shell-command, which may be any sh(1) command. The default is an empty string, which instructs tmux to create a login shell using the value of the default-shell option.
Interactive non-login shell usually never outlive your top level login shell, therefore they can expect any facilities started by it to be available anytime, but this is not the case with tmux:
- you log in to your shell -> your login scripts are run
- you run tmux, do something, detach
- exit your top level shell -> your logout scripts are run
- tmux session is still running but any facilities started by your login shell are not available at this time
- you log in again and re attach from another login shell
- any facilities started by the new login shell may not be visible by tmux because it is still running with the old environment (even though there are commands to update the environment)
Some may think having tmux start login shells is unnecessary anyway because in most setups there are no logout scripts, and login scripts just set up some environment variables.
Furthermore if you append strings to your environment variables in your login scripts (like this: PATH=$PATH:/some/other/path) and they are run more than once in the same process hierarchy you end up with duplicates, and this is most annoying.
But still I tend to think the default makes sense.
See also this: http://openbsd-archive.7691.n7.nabble.com/tmux-and-login-shells-td170948.html