Fixing "Shell Environment is slow" in VS Code
For a while now I have been getting a message when opening VS Code from the command line $. code
that my
VS Code pointed me to this helpful page explaining that the most likely cause was a script in my shell profile taking too long to load.
This is an area I am still not confident in, but after putting up with it for so long (it wasn't stopping me from working) it was finally time to dig in.
Checking my home directory, I found that I had both a bash profile and a zsh profile. I did a quick bit of googling and confirmed that the zsh shell was unlikely to be loading the bash profile unlesss there was a specific reference.
Next, looking at my .zshrc
file everything seemed in order at first, loading NVM, git completion, and then the gopath... nothing crazy.
It then occured to me that I don't use git completion because I didnt think I had gotten around to installing it. A quick test confirmed that it wasn't working, which is what had probably lead to that assumption.
Searching for why git completion might not be working or might be slow at loading, I stumbled on this post on how to install it in the first place.
Skimming this post I noticed that my profile file did not quite match what was recommended. The autoload -Uz compinit && compinit
was missing!
Adding in this command to the profile and then reloading the shell resolved the issue instantly and as an added bonus to my original goal, I now have git command completion working.
Shortly after writing this I saw the comments on the above article from the ZSH creator. All you really need to add is the autoload -Uz compinit && compinit
line to the .zshrc
file for git command completion to work.
Unlike the author of the article, after doing this I did not see any observable slow down.