If your zsh starts very slow

xcv58
xcv58’s blog
Published in
2 min readAug 26, 2016

--

Believe me, you are not alone.

I have the same problem for years. First of all, I switched to zsh around 2013. Zsh is not so good (actually bad) without the Oh My Zsh. Oh My Zsh is really awesome and has a store now. But as I use more and more plugins. Zsh startup time becomes unacceptable. So I switched to Sorin Ionescu’s prezto around 2014. It’s faster. Anyone using Oh My Zsh with slow startup time should try this.

But there’re a lot of frameworks/tools/languages that need to preload during shell startup. Node Version Manager is a good example, it needs 2-3 seconds to load itself. But I probably don’t use node.js daily. It makes no sense to preload it. I wonder that whether there is a plugin/module can do these:

  1. Don’t preload such things
  2. When I need to use them, i.e. type in a command like `npm install react`; it can automatically load nvm
  3. run whatever command I type in after loading nvm

It seems that there’s no generic solution for my problem, probably also your problem.

So I write my own solution: lazy-load. It’s a prezto module. But don’t worry, it only provides two functions (22 lines) and has a fair README file to explain what happens. What you need to do is just provide a preload function and command(s) require the preload function run before your command(s) can execute.

The repo:

Example of how to use:

--

--