SolvedConEmu Windows Subsystem For Linux Bash Specify Startup Directory

ConEmu build: 160724 x64
OS version: Windows 10 x64
Used shell version (Far Manager, git-bash, cmd, powershell, cygwin, whatever): Windows Bash

Problem description

After following this guide I can't seem to find a way to specify a startup directory for bash. Linux paths (or the corresponding Windows path to the Linux directory) result in an error stating the directory name is invalid.

30 Answers

✔️Accepted Answer

@NitroBAY Ops, I made a mistake.

The Windows file system is mounted to Windows Subsystem For Linux(WSL) on /mnt. For example, C:\Users\ is mapped to /mnt/C/Users. So on WSL, you can cd to /mnt/C/Users to access C:\Users\.

In order to make bash cd to particular directory, there are multiple ways.

  • On WSL side, you can add cd /home/NitroBAY/projects to the bottom of your .bashrc or .zshrc file in your home directory.
  • If you want to configure on ComEmu side, you can use "-new_console:d:C:\Users\llan\"%windir%\system32\bash.exe -cur_console:p for example. In this way, if you specify a path inside WSL, C:\Users\llan\AppData\Local\lxss\home\NitroBAY\projects for example, it always redirect to /.
  • The third method, you can configure on ComEmu like %windir%\system32\bash.exe -cur_console:p -c "cd /home/NitroBAY/projects && bash", I missed out bash at first. It might not be a good way, but it works.

Other Answers:

If you guys are using wslbridge in your task as specified on this page for proper ANSI colors, you can use -C per wslbridge help

Usage: /wsl/wslbridge [options] [--] [command]...
Runs a program within a Windows Subsystem for Linux (WSL) pty

Options:
  -C WSLDIR     Changes the working directory to WSLDIR first.
                An initial '~' indicates the WSL home directory.
  -e VAR        Copies VAR into the WSL environment.
  -e VAR=VAL    Sets VAR to VAL in the WSL environment.
  -T            Do not use a pty.
  -t            Use a pty (as long as stdin is a tty).
  -t -t         Force a pty (even if stdin is not a tty).

For me it looks something like

set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pm:/mnt -C "~"

Since this is now the top search result for "conemu wsl startup directory" and the comments are a little noisy; the solution is to add -C "~" to the end of your commands string. If you select the {WSL:bash} task in Startup > Tasks the command text box should look like this:

set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe --wsl -cur_console:pm:/mnt -C "~"

There is easy way to do that. Documented.
No need to harm your .bashrc

For other folks who come across this in attempts to Google a solution, here's the one that worked best for me. I changed the /etc/profile of the WSL to add these lines to the bottom:

if [ "$SHLVL" ] && [ "$SHLVL" = "1" ]; then
  cd ~
fi

For whatever reason, bash.exe is implicitly a login shell. There's no need to add --login to the command line. Per bash documentation, a login shell will source /etc/profile first. I found it helpful to use this as the earliest possible opportunity to fix the incorrect starting directory. It only does so when it's not a nested shell. That is, it's a shell that's started by ConEmu (or some other entity external from the WSL).

Note that you cannot otherwise specify to bash.exe that it should go to a different WSL directory. The "cd && bash -i" trick has subtle failings.

Related Issues:

42
ConEmu Arrow keys not working in Bash for Windows
@ErrantErinaceinae Are you kidding? Months??? The issue was created four days ago! This is absolutel...
37
ConEmu Windows Subsystem For Linux Bash Specify Startup Directory
@NitroBAY Ops I made a mistake The Windows file system is mounted to Windows Subsystem For Linux(WSL...
23
ConEmu WSL2 no longer working after windows update
Thank you This does indeed work You don't need to specify the user (the default one that corresponds...
17
ConEmu Active tab is hard to see
So here's a more concrete proposal: have tab templates support a new %* token for the Selected tab w...
12
ConEmu sometimes ssh crashes when using vi
I got the same problem in a ConEmu tab Doing the same SSH from a new bash window worked as expected ...
8
ConEmu Scroll wheel does not work in tmux in WSL
@Maximus5 It seems that the culprit here is the set -s escape-time 0 in .tmux.conf! escape-time time...
574
terminal Typing inside of the default WSL terminal feels amazing, why is it better than every other app?
I really do not mind when someone comes by and decides to tell us that we're doing a good job at som...
123
pm2 How do I call `pm2` to check if a process with given name is running?
For me the problem was that any of the above solutions I tried gave a non-zero exit code which would...
107
ripgrep Add support for replace in files
This is more easily accomplished using sed than I think people realize sed is quite a beast and is n...
92
terminal Guide for build and installation
This information should be included in the Building the Code section of the README file. ...
85
terminal error 0x80070002 when launching `powershell.exe'
Just add the path of the power shell to the environment variable Thank you It works! %systemroot%\Sy...
75
gitsome Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7SrToZ/gitsome/
I had the same problem on OSX and Solve my issue (I have both python versions installed). ...
71
bat Ubuntu install error when rg is installed also
As a workaround one can use sudo apt install -o Dpkg::Options::=--force-overwrite bat ripgrep (taken...
70
terminal Move the solution to VS2019 and v142 toolset
As mentioned in README (also related to #534) If you're running VS2019 ...
48
pm2 How do you run a TypeScript app with ts-node parameters?
I am using pm2 start ts-node -- -P tsconfig.server.json ./server/index.ts I normally run my app with...
46
pm2 Latest Socket.io and pm2 causing issues when using -i max
I know this one is old and closed When I launch my app.js file via pm2 start app.js -i max I get the...
43
terminal MEGATHREAD: Breaking settings changes in version 0.11!
Out of curiosity BREAKING SETTINGS CHANGES IN 0.11 BREAKING CHANGE We've deleted a lot of legacy set...
42
terminal Windows Terminal keeps forgetting/can't find my default WSL Ubuntu profile
Happened to me (seemingly) after updating Docker for Windows Haven't had any issues with WSL2 for mo...
40
ripgrep hidden files to be searched by default
The following is @okdana's solution but with the .git folder remaining ignored: ...
38
pm2 Systemctl error: PID file not readable (yet)
I have this issue on Arch Linux with Node.js v9.6.1 and pm2 2.10.1 It is strange that it DOES create...
37
terminal Terminal hangs on exit with 'process exited with code 127' message
@carragom Oh that explains it - closeOnExit is a Profile setting Hi! I've noticed that on newer rele...
35
pm2 pm2 start npm -- start error
This is still happening on my Windows 10 machine Whatever globally installed program from npm I try ...
33
bat [fzf] Bat is awesome, but
It's so awesome but whyyyyy Whenever bat detects a non-interactive terminal it will fall back to pri...
28
pm2 Can't supply command line arguments to script
A standard unix way of doing such things would be something like that: pm2 start script.js -- -d 1 w...
27
pm2 pm2 for java - Shell script launching java process, stop doesn't stop the java process
Here you go Can we use pm2 for java? If yes can you provide a working example? ...
26
PowerShell Equivalent of bash set -e
$erroractionpreference = stop only works if Write-Error is called (such as an exception is raised) I...
24
terminal Alt arrow keys do nothing; key unbinding broken?
This behavior is due to #3585 Proper expected behavior is restored with the following: ...
23
ripgrep ripgrep no way to exclude directory e.g. Tests and search for all *.c files
@sumonto you're correct $ rg -w str1 -tc -g '!tests/*' would do what you want So is that not working...
23
pm2 Startup is not starting pm2 daemon and saved process
I had this issue too wanting to run pm2 as root i installed pm2 as global package on ubuntu (aws ins...
23
exa Static binary downloaded from release not working, lacking libhttp_parser
A sudo apt install libhttp-parser2.1 fixed it for me on ubuntu17 but I don't see why this tool would...
22
pm2 Spawning PM2 daemon with pm2_home=/home/tealou/.pm2
I got the same problem i had fixed it.. It's because of the version conflict Now i use node version ...
22
http server it does not work when i reload the browser after navigating to a route.
@thornjad Great it works with SPA: http-server --gzip --proxy http://localhost:8080? ...
21
ripgrep Option for outputting absolute paths
I don't see how that's a niche problem judging from others mentioning here they have the with the sa...
21
PowerShell pwsh as a dotnet global tool exhibits very unusual behavior with Ctrl-C
Unless Scoop is using the dotnet global tool wrapper shipped with PowerShell this is likely an issue...
21
winget cli winget should install an app if there is an exact match (eg 'git')
Fall into the pit of success Search = case insensitive non-exact match Install = case insensitive ex...
20
http server The header content contains invalid characters?
\http-server\node_modules\ecstatic\lib\ecstatic\etag.js I install the package and write a simple htm...
20
micro copy paste doesn't work well
Thanks @SrMordred this fixed this issue for me too! Hello I like where micro is going It's truly the...
19
pm2 Multiple instance of an app (in fork mode) bound to different ports + load balancing using nginx
I was able to launch multiple instances of the same script using json config: pm2.json: ...
19
winget cli Permission Denied when running from bash
FYI a easy workaround is to add e.g to your .bashrc and alias using winpty (included by default in m...
18
terminal Vim Cursor shape stays underscore. Not able to change it
@tuyenpm9 that's no $PS1 that's a %PROMPT% setting in CMD: https://github.com/zadjii/keep/blob/maste...
17
terminal It is hard to find Microsoft.VCLibs.140.00.UWPDesktop
@atom0s Thanks for the info The store.rg-adguard.net seemed a bit shady to me but I can confirm that...
17
terminal Azure Cloud Shell is readded to the profiles.json file after I remove it and restart terminal.
@Alacritous thanks for not including those invectives Steps to reproduce Open profiles.json through ...
17
terminal Large number of "'function' is not a member of 'std'" errors
If you're trying to build on VS19 add #include <functional> below #include <filesystem> in LibraryIn...
16
goaccess Support structured log formats such as JSON
Native JSON support has been added Feel free to build from development to test this out It will be p...
16
terminal when i open the windows terminal ,its show [error 0x80070002 when launching powershell.exe']
It seems that your PATH environment variable may be damaged and not contain the Windows PowerShell d...
16
terminal How Do I Build it to Begin With?
Steps: Follow #449 (https://github.com/microsoft/Terminal/pull/449/files) If using VS2019 open the p...
15
pm2 pm2 cluster mode fails to start because `Error: ENOENT, no such file or directory` for process.cwd()
pm2 update solves. same as #1244 This always happen when stop the old server replace the source code...
15
pm2 Too Many Unstable Restarts
Are you using nvm or n to install pm2? I think it's due to a bad node version from the modules Pleas...
15
winget cli 0x801901f4 : Internal server error (500) when I try to execute winget list and winget install (Source is down)
The newstore source is down which breaks the client entirely unless you add --source winget to all o...
14
PowerShell Install-Module errors on install of Azure and AzureRM modules - MacOsX
I followed @alexandair's advice and it worked A step by step though is that you'll need to do the fo...