5

When I open the WSL by clicking on its icon I need it to be opened in a certain directory (of course one that is more useful than System32), so I add a cd destination in my .bashrc. But then the "Open Linux Shell Here" option (available when you hold the Shift key on keyboard and right-click on any folder is also being redirected to that destination, which is undesirable. Is there a way I can detect this case in my .bashrc script and let it behave as it should?

In short, I need to know when the shell has been opened by the option in Shift+Right Click inside a folder, so that I can avoid changing the working directory to another one.

I'm using WSL-Ubuntu 18.04 LTS and GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu).

3

I would change the ~/.bashrc enhancement to something like this:

CurrDir="$(pwd)"
if [[ "$CurrDir" == "$SystemDir" ]]
then
    cd /path/to/sensible-dir-name
Fi

Where $SystemDir is your System32 directory. Always remember how \ and / differ between Windows and Linux paths:

Suggests using:

sed -e 's#^J:##' -e 's#\\#/#g'

That said in your instance you could probably hard-code the path.

  • You can use wslpath for the conversion: `if [[ "$CurrDir" == $(wslpath -u "$SystemDir") ]] – Carlos Rafael Ramirez Aug 2 '19 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.