Skip to content

"Open a linux shell" and genie

Alistair Young edited this page Jun 20, 2020 · 1 revision

The Problem

As you may have noticed if you read A note on environment variables and cwd, when genie is started as a login shell, the environment is made anew and neither the Windows $PATH nor cwd are preserved. (See that article for details.) This causes problems for the "Open a linux shell" context menu item provided by WSL if you are also making use of Automatically start genie on every shell session or otherwise automatically running genie to get a login shell from your .profile/.login, since in this case, you want cwd (and probably the Windows $PATH elements) to be preserved.

The Solution

Make it use genie -c instead to run your default shell as a non-login shell. Here's how:

  1. Open Registry Editor as an administrator.

Repeat the following steps for the following three registry keys

  • HKEY_CLASSES_ROOT\Directory\Background\shell\WSL
  • HKEY_CLASSES_ROOT\Directory\Background\shell\WSL\command
  • HKEY_CLASSES_ROOT\Drive\shell\WSL\command
  1. If you have not done so already, open the permissions page for this key. You will need to, first, use the advanced permissions dialog to change ownership of the "command" subkey to the local Administrators group. Be sure to select the "Replace owner on subcontainers and objects" checkbox to change permissions on the value, too.

  2. If you have not done so already, change permissions for Administrators on the "command" subkey from "Read" to "Full Control".

  3. The "(Default)" value for the "command" subkey is, normally, set to

wsl.exe --cd "%V"

which starts a vanilla WSL session in the current directory. To instead start a genie inside-bottle session in the current directory, change the value to this:

wsl.exe --cd "%V" genie -c "sh -c `getent passwd $LOGNAME | cut -d: -f7`"

Once these changes are made, they take effect immediately. Please note the constraints mentioned under A note on environment variables and cwd.