Cygwin Tmux always creates new windows in HOME directory

Wed 08 October 2014 / In categories Dev Tools

Cygwin, tmux

Tmux is a convenient terminal multiplexer, not until recently Cygwin has packed Tmux in its distribution source, now we can install Tmux from setup-x86{_64}.exe, the package installer provided by Cygwin.

One problem I experienced while using tmux is that: every time I created a new window in Tmux, the working directory is always HOME, even if I specified the startup directory in the option:

tmux new-window -c "/target/directory"

Having examined this problem for a while, I can now tell what is wrong.

If a shell is launched as a login shell in Cygwin, the working directory is always set to HOME by the default configuration.

To avoid the unexpected behaviour, we can configure Tmux like this:

set -g default-command $SHELL

Add the above line to your ~/.tmux.conf to make it permanent.

The rationale can be found in the manpage of tmux:

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.

Thus, setting a non-empty default-command prevents the shell being made into a login shell, the problem is worked around.

Load Disqus Comments