5

I love ZSH shell and its themes but it is very slow. It takes 7 to 10 seconds to load. I also use it as a integrated terminal in VS Code even though it's slow to load. Here is a copy of my .zshrc file.

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
export PS1="[%* - %D] %d %% "


# Set name of the theme to load. 
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="agnoster"
DEFAULT_USER=13000

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for 
  completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked 
  files
# under VCS as dirty. This makes repository status check for large 
  repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution 
  time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-
  zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
  plugins=(git)

# User configuration

export PATH=$HOME/bin:/usr/local/bin:$PATH
# export MANPATH="/usr/local/man:$MANPATH"

source $ZSH/oh-my-zsh.sh


# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

prompt_dir() {
  prompt_segment blue black "${PWD##*/}"
}

EDIT :: I found 2 oh-my-zsh.sh file in my cygwin directory so here are the both of them.

First one

# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f 
$ZSH/tools/check_for_upgrade.sh
fi

# Initializes Oh My Zsh

# add a function path
fpath=($ZSH/functions $ZSH/completions $fpath)

# Load all stock functions (from $fpath files) called below.
autoload -U compaudit compinit

: ${ZSH_DISABLE_COMPFIX:=true}

# Set ZSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$ZSH_CUSTOM" ]]; then
    ZSH_CUSTOM="$ZSH/custom"
fi

# Set ZSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
if [[ -z "$ZSH_CACHE_DIR" ]]; then
  ZSH_CACHE_DIR="$ZSH/cache"
fi


# Load all of the config files in ~/oh-my-zsh that end in .zsh
# TIP: Add files you don't want in git to .gitignore
for config_file ($ZSH/lib/*.zsh); do
  custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  source $config_file
done


is_plugin() {
  local base_dir=$1
  local name=$2
  test -f $base_dir/plugins/$name/$name.plugin.zsh \
    || test -f $base_dir/plugins/$name/_$name
}
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin ($plugins); do
  if is_plugin $ZSH_CUSTOM $plugin; then
fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  elif is_plugin $ZSH $plugin; then
    fpath=($ZSH/plugins/$plugin $fpath)
  fi
done

# Figure out the SHORT hostname
if [[ "$OSTYPE" = darwin* ]]; then
  # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
  SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || 
SHORT_HOST=${HOST/.*/}
else
  SHORT_HOST=${HOST/.*/}
fi

# Save the location of the current completion dump file.
if [ -z "$ZSH_COMPDUMP" ]; then
  ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
fi

if [[ $ZSH_DISABLE_COMPFIX != true ]]; then
  # If completion insecurities exist, warn the user without enabling 
completions.
  if ! compaudit &>/dev/null; then
    # This function resides in the "lib/compfix.zsh" script sourced above.
    handle_completion_insecurities
  # Else, enable and cache completions to the desired file.
  else
    compinit -d "${ZSH_COMPDUMP}"
  fi
else
  compinit -i -d "${ZSH_COMPDUMP}"
fi

# Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do
  if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
    source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
    source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  fi
done

# Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  source $config_file
done
unset config_file

# Load the theme
if [ "$ZSH_THEME" = "random" ]; then
  themes=($ZSH/themes/*zsh-theme)
  N=${#themes[@]}
  ((N=(RANDOM%N)+1))
  RANDOM_THEME=${themes[$N]}
  source "$RANDOM_THEME"
  echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
else
  if [ ! "$ZSH_THEME" = ""  ]; then
    if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
      source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
    elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
      source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
    else
      source "$ZSH/themes/$ZSH_THEME.zsh-theme"
    fi
  fi
fi

The second one is

# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f 
$ZSH/tools/check_for_upgrade.sh
fi

# Initializes Oh My Zsh

# add a function path
fpath=($ZSH/functions $ZSH/completions $fpath)

# Set ZSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$ZSH_CUSTOM" ]]; then
    ZSH_CUSTOM="$ZSH/custom"
fi

# Set ZSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
if [[ -z "$ZSH_CACHE_DIR" ]]; then
  ZSH_CACHE_DIR="$ZSH/cache/"
fi


# Load all of the config files in ~/oh-my-zsh that end in .zsh
# TIP: Add files you don't want in git to .gitignore
for config_file ($ZSH/lib/*.zsh); do
  custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  [ -f "${custom_config_file}" ] && config_file=${custom_config_file}
  source $config_file
done

# Load all of your custom configurations from custom/
for config_file ($ZSH_CUSTOM/*.zsh(N)); do
  source $config_file
done
unset config_file

is_plugin() {
  local base_dir=$1
  local name=$2
  test -f $base_dir/plugins/$name/$name.plugin.zsh \
    || test -f $base_dir/plugins/$name/_$name
}
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin ($plugins); do
  if is_plugin $ZSH_CUSTOM $plugin; then
    fpath=($ZSH_CUSTOM/plugins/$plugin $fpath)
  elif is_plugin $ZSH $plugin; then
    fpath=($ZSH/plugins/$plugin $fpath)
  fi
done

# Figure out the SHORT hostname
if [[ "$OSTYPE" = darwin* ]]; then
  # OS X's $HOST changes with dhcp, etc. Use ComputerName if possible.
  SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || 
SHORT_HOST=${HOST/.*/}
else
  SHORT_HOST=${HOST/.*/}
fi

# Save the location of the current completion dump file.
if [ -z "$ZSH_COMPDUMP" ]; then
  ZSH_COMPDUMP="${ZDOTDIR:-${HOME}}/.zcompdump-${SHORT_HOST}-${ZSH_VERSION}"
fi

# Load and run compinit
autoload -U compinit
compinit -i -d "${ZSH_COMPDUMP}"

# Load all of the plugins that were defined in ~/.zshrc
for plugin ($plugins); do
  if [ -f $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh ]; then
    source $ZSH_CUSTOM/plugins/$plugin/$plugin.plugin.zsh
  elif [ -f $ZSH/plugins/$plugin/$plugin.plugin.zsh ]; then
    source $ZSH/plugins/$plugin/$plugin.plugin.zsh
  fi
done

# Load the theme
if [ "$ZSH_THEME" = "random" ]; then
  themes=($ZSH/themes/*zsh-theme)
  N=${#themes[@]}
  ((N=(RANDOM%N)+1))
  RANDOM_THEME=${themes[$N]}
  source "$RANDOM_THEME"
  echo "[oh-my-zsh] Random theme '$RANDOM_THEME' loaded..."
else
  if [ ! "$ZSH_THEME" = ""  ]; then
    if [ -f "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" ]; then
      source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
    elif [ -f "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" ]; then
      source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
    else
      source "$ZSH/themes/$ZSH_THEME.zsh-theme"
    fi
  fi
fi

Do not mind the long post :D.

alex
  • 479,566
  • 201
  • 878
  • 984
Pramesh Bajracharya
  • 2,153
  • 3
  • 28
  • 54

3 Answers3

1

I've installed babun on my Windows 10 machine.

Disabling bash autocompletion jobs slightly improved my loading time. I renamed all my files to ".bk" extensions in the "bash_completion.d" directory.

{ ~ }  » ls -ltr /etc/bash_completion.d                                                         ~
total 68
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users   998 Jun 23  2015 vim-completion.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users 44924 Jun 23  2015 svn.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users  1200 Jun 23  2015 gvim-completion.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users  2609 Jun 23  2015 gsettings.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users  1356 Jun 23  2015 gresource.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users   935 Jun 23  2015 gdbus.bk
-rwxrwx---+ 1 m.ortiz.montealegre Domain Users  1389 Jun 23  2015 gapplication.bk

Also debugging is a good option with strace to see what's going on while Cygwin is loading, please check this question.

EDIT:

About Babun tweaking

A tool you could use to check your installation is documented in the babun website, use babun check maybe this offer you some clue:

{ ~ } » babun check                                                                          ~
Executing babun check
Prompt speed      [SLOW]
Hint: your prompt is very slow. Check the installed 'BLODA' software.
Connection check  [OK]
Update check      [OK]
Cygwin check      [OK]

I don't know if you performed some tweaking in your babun installation, please check your ~/.babunrc file and verify you've disabled auto-updates and startup checks (do not enable them):

# JVM options
export JAVA_OPTS="-Xms128m -Xmx256m"

# Modify these lines to set your locale
export LANG="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"

# Uncomment these lines to the set your machine's default locale (and comment out the UTF-8 ones)
# export LANG=$(locale -uU)
# export LC_CTYPE=$(locale -uU)
# export LC_ALL=$(locale -uU)

# Uncomment this to disable daily auto-update & proxy checks on startup (not recommended!)
# export DISABLE_CHECK_ON_STARTUP="true"

# Uncomment to increase/decrease the check connection timeout
# export CHECK_TIMEOUT_IN_SECS=4

# Uncomment this lines to set up your proxy
# export http_proxy=http://user:password@server:port
# export https_proxy=$http_proxy
# export ftp_proxy=$http_proxy
# export no_proxy=localhost

About Cygwin

There are several tweaks here and here you could explore for Cygwin if you aren't happy debugging with Strace.

I think you should abstract the "babun" thing and don't forget about the embeded Cygwin which I think is what you really what to speed up, the babun core is a Cygwin implementation with some changes:

The core of Babun consists of a pre-configured Cygwin.

Miguel Ortiz
  • 1,412
  • 9
  • 21
  • **bash auto completion** is one of the major feature that I use. It's one of the main reason why I love babun. Disabling that is a no no :) . Is there some other tips? Please do humour me :D. Thanks! – Pramesh Bajracharya Jun 28 '17 at 03:32
  • Running **strace** gave me this huge log. I literally have to scroll 23 times to reach the top. What am I supposed to do ? – Pramesh Bajracharya Jun 28 '17 at 04:19
  • Also I tried renaming every file in `bash-completion.d` to `.bak` extension. Load time still the same. – Pramesh Bajracharya Jun 28 '17 at 04:24
  • Pramesh, strace allows you to see all the system calls. Debugging that log you can find what is beign loaded in your environment and disable or improve the things that take too long. – Miguel Ortiz Jun 28 '17 at 16:54
  • The **Strace** log is waaaaay too long. It might take me 3 - 4 days to debug it but I'll try it sooner or later. Is there any other way? Thanks for the help. – Pramesh Bajracharya Jun 29 '17 at 02:10
0

Often the long load times lead to the framework used by the shell.

$ zsh -xv which will outprint the things loaded on runtime. You can see which plugin/process needs the longest time to load and react.

Else did you try cleaning the asl files?

http://osxdaily.com/2010/05/06/speed-up-a-slow-terminal-by-clearing-log-files/

nmanh
  • 325
  • 2
  • 14
  • using `antigen` did no good. Loading time is nearly the same. Earlier it took around 7 seconds. It's the same after `antigen`. Also using `zsh -rv` gave me a huge log which I have no idea of. The `asl` clearing is for mac OS I guess as it didn't work for me. Thanks! Any other tips you could suggest? I will try everything :D – Pramesh Bajracharya Jun 28 '17 at 04:22
  • Did you use antigen and removed oh my zsh? Usually the start time should be fast at least. How are other shells? Bash? Are they faster? Try `https://github.com/getantibody/antibody` was written, because antigen was too slow. – nmanh Jun 28 '17 at 21:00
  • My other shells ie `cmd, git bash` are fast. My slow shells are `Bash on windows and Babun` using **oh-my-zsh** . – Pramesh Bajracharya Jun 29 '17 at 02:04
  • So `bash` is slow as well? Is zsh without `oh-my-zsh` slow as well? Did you try `Antibody`? Did you try the 'babun' theme? – nmanh Jun 29 '17 at 07:21
  • **bash** by it's own is fast. When introduced with **oh-my-zsh** it's slow. – Pramesh Bajracharya Jun 29 '17 at 17:10
  • Did you try to use `zsh` without `oh-my-zsh`? – nmanh Jun 29 '17 at 19:42
0

Run zsh -xv command and watch verbose output like watching television (do not disturb with mouse, keys). At the points verbose output will get slower, if possible remove that plugin or check for bugs. Then run source .zshrc. Again verbose output will start. Launch a new shell window. You'll understand that the loading becoming faster.

I am saying about slow Oh-My-ZSH / ZSH part. I am not Windows user, you should exclude any exclusively Windows related matter. With Homebrew, iTerm, those minor problems are regular matter. Oh-My-ZSH with beautiful stuffs loads pathetically slower on Mac with plugins, themes. Nothing new. You can search the whole internet and you'll find lot of Mac users & slow Oh-My-ZSH. You need to search issues with slow ZSH or Oh-My-ZSH not slow babun on windows. Mac users with Oh-My-ZSH are far higher in number. Plus there are GNU/Linux users.

You can read this Github discussion and this post. All fixes are for making slightly faster.

All will give you instructions towards generic, like we will say to make DISABLE_AUTO_UPDATE="true" active, ZSH history size smaller and so on. Run :

cd ~
export HISTSIZE=2000
export HISTFILE="$HOME/.history" 
export SAVEHIST=$HISTSIZE
setopt hist_ignore_all_dups
# reload once
source .zshrc
# check
cat .history 
  • the links you provided are the one's I've gone through already with no luck. Running `zsh in debug mode` ie. `zsh -xv` gave me a huge log in less than a second. What am I supposed to do ? In the link you provide it suggest to watch where the terminal freezes but my doesn't freeze at all. I have executed your provided commands too. I''ll let you know if any decrement in load time is noticed. Thank you. Also you are right , with all fancy theme and plugins `zsh` is sure to be slow and there are a lots of post about it. But those post are regarding Linux and MAC not windows :P :( – Pramesh Bajracharya Jun 28 '17 at 11:50