Today I Learned

5 posts about #zsh

Lazy-load NVM to speed up zsh initialization

UPDATE Once appending --no-use, ensure to source $NVM_DIR/ when actually needed. For example, yarn install will complain node: No such file or directory

I was curious as to why the zsh initialization was so slow. After some benchmarking .zshrc, I learned that oh-my-zsh and NVM were the main source of slow-down. For oh-my-zsh, I'm trying to see if I can avoid loading plugins that I rarely use to cut some time. However for nvm, simply passing `--no-use the following will make a big difference.

[ -s "$NVM_DIR/" ] && . "$NVM_DIR/" --no-use

Benchmarking with bash's buil-in time command...

Before --no-use:

❯ for i in $(seq 1 5); do /usr/bin/time zsh -i -c exit; done
        1.43 real         0.65 user         0.62 sys
        2.42 real         0.66 user         0.61 sys
        1.42 real         0.65 user         0.61 sys
        1.42 real         0.65 user         0.61 sys
        2.43 real         0.66 user         0.62 sys

After --no-use:

❯ for i in $(seq 1 5); do /usr/bin/time zsh -i -c exit; done
        0.48 real         0.26 user         0.17 sys
        0.46 real         0.25 user         0.16 sys
        0.46 real         0.25 user         0.16 sys
        0.46 real         0.26 user         0.16 sys
        0.49 real         0.27 user         0.17 sys


Send commands to all panes in iTerm


I just edited my shell profile (~/.zshrc). Now I need to remember to reload any pane that needs the changes.


Send commands to all panes:

  1. Cmd + Shift + I
  2. source ~/.zshrc


Skip duplicate history entries in zsh

In zsh, pressing UP searches through the history and brings up all matching commands, even if they are duplicates. That means, sometimes you need to press UP many times to actually find a previous match.

However, it is possible to disable this behaviour and skip duplicate entries from the history. To do that, add one line to your ~/.zshrc:

Mass replace and copy by file extension


I just cloned a Rails project. There are a bunch of files with the .yml.sample extension under the config directory.

I'd like to copy all those files without the .sample prefix.


zsh functions to the rescue!

Add this to your .zshrc file:

autoload -U zmv

Then run:

zmv -C 'config/(*.yml).sample' 'config/$1'

By default, zmv will move files. -C puts it in copy mode.

For more info:

man zshcontrib

Oh-My-Zsh Plugins List

I feel like I just discovered the Internet when I look at this page: