In WSL2, tab completion is very slow on executable files and in certain directories
a<tab>
# Wait 5-10 seconds and it will eventually show the completion menu
The issue is much more evident when tab completing a specific file that is in the immediate directory and thus doesn't require the menu to appear:
cd ~
touch foo
chmod +x foo
./fo<tab>
# Wait 5-10 seconds and it will eventually complete the word foo
I'm not sure if this is a zsh issue or a prezto issue, however if I disable prezto and use vanilla zsh, the tab completion is instant. The vanilla tab completion doesn't use the menu however, so it could also be the menu's fault, but I'm not sure how to verify that.
I have noticed that WSL, by default, puts a lot of /mnt/c directories (such as /mnt/c/Windows/) on $PATH.
~ ❯❯❯ echo $PATH | tr ':' '\n'
/usr/local/bin
/usr/local/sbin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/mnt/c/Windows/system32
/mnt/c/Windows
/mnt/c/Windows/System32/Wbem
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/
/mnt/c/Windows/System32/OpenSSH/
/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR
/mnt/c/WINDOWS/system32
/mnt/c/WINDOWS
/mnt/c/WINDOWS/System32/Wbem
/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/
/mnt/c/WINDOWS/System32/OpenSSH/
/mnt/c/Users/Fryguy/AppData/Local/Microsoft/WindowsApps
If I remove those directories, then tab completion is fast. For now, as a workaround I have the following in my profile which works:
export PATH=$(echo $PATH | tr ':' '\n' | grep -v "/mnt/c/" | tr '\n' ':')
With that workaround in place, everything is fast, however I can kind of force the issue anyway by doing:
cd /mnt/c/Windows/System32
a<tab>
# Wait 3-5 seconds for the completion menu to appear
My guess is something about these Windows directories is overloading completion, but I have no idea how to narrow this down any further.
I've also tried the following to no effect:
sudo updatedbrm -rf ~/.zcompdump*zsh 5.4.2 (x86_64-ubuntu-linux-gnu)Ubuntu 18.04.4 LTS \n \l on WSL2 - Microsoft Windows [Version 10.0.19592.1001]Faced the same issue here as well. completion gathers some windows specific "exe" binary as well. Basically WSL2 has windows path as well, and that where it get really slow.
Disable windows paths with appendWindowsPath in wsl.conf:
https://devblogs.microsoft.com/commandline/automatically-configuring-wsl/
Then just make aliases to the stuff you use from windows (explorer.exe, vscode etc.)