2

From some point, suddenly (I guess after an Ubuntu update?), it starts in the root directory when I open a new terminal. I want to start from my home directory as before.

The below is my shell script(I removed all the comments). I am running Ubuntu on WSL2 on Windows 10

export ZSH="/home/myubuntu/.oh-my-zsh"
ZSH_THEME="bira"
DISABLE_LS_COLORS="true"
plugins=(git)

source $ZSH/oh-my-zsh.sh

alias tre='tree -a -C -I '\''node_modules|.git'\'' --dirsfirst'

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

#cd workspace
if [ "$PWD" = "$HOME" ]; then cd workspace; fi

# added by travis gem
[ ! -s /home/myubuntu/.travis/travis.sh ] || source /home/myubuntu/.travis/travis.sh

This is Ubuntu info

╰─$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

Anyone knows how to fix this?

9
  • Does your home directory exist? If it doesn't (like if /home was not mounted), then the default current working directory is probably /
    – ubfan1
    Dec 27, 2021 at 5:11
  • I don't have WSL2 up and running so I can't verify this but if you have access to your settings.json file, change the starting directory path to /home/username where username = your actual username. Example: /home/taeil
    – mchid
    Dec 27, 2021 at 5:44
  • I found the answer here and they reference another similar answer that involves using a path with backslashes instead
    – mchid
    Dec 27, 2021 at 5:46
  • @ubfan1 it exists.
    – Tommy
    Dec 27, 2021 at 7:23
  • @mchid Thank you, that is the problem I have. WOW, you have much better googling skills than me, I couldn't find it by googling for hours.
    – Tommy
    Dec 27, 2021 at 7:24

1 Answer 1

1

I see in the comments that you got this working, but there are several ways to do this under Windows Terminal:

  • Under Windows 10 21H2 and Windows 11, you can specify a Linux directory instead of the Windows path for startingDirectory. So now /home/taeil will work (assuming you are upgraded). See this answer on Stack Overflow for details and a link to the Microsoft Doc.

  • Under previous versions, you do need to use the Windows format \\wsl$\ path (quoted) as noted in the comments. In your case, it looks like this would be \\\\wsl$\\Ubuntu\\home\\taeil

  • Personally, for using your Linux home directory as a starting point, I recommend this technique (my answer in that same Stack Overflow question). Just start wsl with wsl ~ to start in your home directory.

  • Also, with Windows 10 21H2 and Windows 11, wsl --cd ~ works.

2
  • Thanks, I fixed following the comment. but still good to know various ways. startingDirectory: "~" seems the best way to me.
    – Tommy
    Dec 28, 2021 at 4:05
  • @Taeil Ah, if only it worked. I just tried it, and it doesn't :-/. I would have thought that it would pass the startDirectory to the wsl --cd command, but apparently not. I usually just edit the commandLine property myself and force it to wsl ~, which I do know works, but if you want to use startingDirectory':/home/taeil` is probably the next best thing. Dec 28, 2021 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .