LoginSignup
11

More than 1 year has passed since last update.

posted at

updated at

wsl2になってコマンドの補完が重いと感じたらwindows側のPATHを消して必要なものだけシンボリックリンクを貼ろう

そもそもなぜ重いのか?

私はこういう理由が一つあると考えます。

  1. wsl側からwindows側のファイルを見るのに9pを使っている。
  2. 9pは遅い
  3. Shellは補完をする時、実行権限のあるファイルを検索している。
  4. wsl側から見たwindows側のファイルはファイルシステムの違いから777に設定されている。
  5. よって、shellは遅い9pを使いながら、毎回dllなどの実行できないファイルまでも検索してくる。

よって、重い!!

wsl1ではwindows側のファイルは直接触れていて、9pを通していなかったので軽かったのだと考えられます。

ではどうすればよいのか?

検索するファイルを最小限にすれば良い。

やり方

windows側のPATHを消す

/etc/wsl.conf
[interop]
appendWindowsPath = false

適当なPATHの通っているディレクトリーにwindows側のシンボリックリンクを貼る。

bash
# 適当なディレクトリを作成してパスを通した。
mkdir windows_commands
export PATH = $PATH:$HOME/windows_commands
cd ~/windows_commands

# シンボリックリンクを貼っていく
ln -s "/mnt/c/Users/morihaya/AppData/Local/Programs/Microsoft VS Code/bin/code"
# wsl側からdocker を使うなら必要
ln -s "/mnt/c/Program Files/Docker/Docker/resources/bin/docker-credential-desktop.exe"
ln -s "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"

終わり

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
11