4

I love tmux, but whenever I need to create a split with a new pane or a new window it has to run my zsh init scrips and .profile, etc. And they take about a few seconds to run. Initializing stuff like fasd etc.

Is it possible to make it faster to start?

  • 1
    Something appears wrong, a new shell should be pretty much instantaneous. The usual way to arrange things is to have things which take a long time happen in .profile and only run .zshrc in new shells. Is it only fasd which is slowing your startup? At the moment your question is very broad so it is hard to help. – icarus Dec 11 '16 at 17:12
  • 1
    Going by your description, zsh's startup time is the issue, not something related to tmux. – Gilles 'SO- stop being evil' Dec 11 '16 at 23:08
  • 1
    Uninstall Oh-My-Zsh... – jasonwryan Dec 11 '16 at 23:09
  • fasd pronounced fast, if it isn't and you don't need it make sure you put don't execute in your .profile depending on $TMUX being set – Anthon Dec 18 '16 at 22:18
6

“Initializing stuff like fasd etc.” — well, doing complex things is bound to take some time.

Here are a few generic tips to speed up zsh startup:

  • Only run commands you actually need. Don't use huge generic frameworks like oh-my-zsh that define yet another configuration layer that pretends to cater for everyone (but actually doesn't, anyway).
  • Avoid running subprocesses. For short string manipulation, use zsh's built-in constructs, not cut, sed, awk, etc.
  • Use byte-compiled files for anything large.
  • Make sure that completion information is cached: pass -d to compinit.
  • Load things lazily, i.e. on first use. Use autoload liberally.

To find what's taking so long, profile your .zshrc.

  • You can get some measurements from the zsh profiler. Add zmodload zsh/zprof at the top of your .zshrc and run zprof.
  • You can trace what zsh is doing (note that the tracing itself will slow things down, but in a mostly-uniform manner). Add setopt prompt_subst; zmodload zsh/datetime; PS4='+[$EPOCHREALTIME]%N:%i> '; set -x at the top of your .zshrc.

Not the answer you're looking for? Browse other questions tagged or ask your own question.