Install Oh My Zsh with pure and auto suggestions for Windows

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes,…
This post will show How to Install Oh My Zsh with theme pure and plugin auto suggestions for Windows

Before install

To run Zsh on Windows, you must install Git bash for Windows. Make sure Create symbolic link permission added your computer user in Group Policy!

Download and Install Zsh

First, download package Zsh from official MSYS2 Packages https://packages.msys2.org/packages/zsh?repo=msys&variant=x86_64
Look at section Installation > File. File name like zsh-5.9-3-x86_64.pkg.tar.zst

Extract downloaded file by Right click > Extract All… Or use software like 7-Zip
Next Copy two folder named etc and usr extracted to your install Git bash location, default is C:\Program Files\Git

You need start zsh by default each time open Git bash, it’s so easy!
Open folder C:\Users\your_computer_user Right click > New > Text Document > name it .bashrc and paste below content:

if [ -t 1 ]; then
  export ZSH_DISABLE_COMPFIX="true"
  exec zsh
fi

Final just Start Git bash, if it showing script zsh-newuser-install simple press 0 then run command echo $0 to verify zsh is default now.

Install Zsh

Install Oh My Zsh with theme and plugins

We highly recommend use Oh My Zsh with Pure theme and plugins zsh-autosuggestions, zsh-syntax-highlighting, zsh-completions

Just run follow command in Git bash for download:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Install Oh My Zsh

Then download theme and plugins:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-completions.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions
git clone https://github.com/sindresorhus/pure.git ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/themes/pure

When download completed, last step is config for all working smooth on Windows!
Close all current Git bash process, then open C:\Users\your_computer_user\.zshrc with your text editor, like Notepad.

First, disable History file lock and ignore completion ORIG_HEAD because we are working on Windows, different working mechanism from Unix/Linux make Zsh slow. Paste to first line of .zshrc

setopt HIST_FCNTL_LOCK
zstyle ':completion::' ignored-patterns '*ORIG_HEAD'

Next, zsh-syntax-highlighting plugin has problem when using msys on Windows, make it slow down. So we must wrapper function and disable query Windows Active Directory (AD) domain. Paste to end line of .zshrc

# https://github.com/zsh-users/zsh-syntax-highlighting/issues/431#issuecomment-2735590987
functions[_zsh_highlight_main_highlighter_check_path]='
  (){
    if [[ $OSTYPE == 'msys' ]]; then
    if [[ $arg == \\\\* || $arg == //* ]]; then
      REPLY=path
      return 0
    fi
    fi
    '$functions[_zsh_highlight_main_highlighter_check_path]';
    } "$@";
  local exit_code=$?
  return $exit_code'
functions[_zsh_highlight_main__type]='
  (){
    if [[ $OSTYPE == 'msys' ]]; then
    if [[ $arg == \\\\* || $arg == //* ]]; then
      REPLY=path
      return 0
    fi
    fi
    '$functions[_zsh_highlight_main__type]';
    } "$@";
  local exit_code=$?
  return $exit_code'

Last, config theme and plugins downloaded before.
Find line plugins=(...) add zsh-autosuggestions zsh-syntax-highlighting

Replace line source $ZSH/oh-my-zsh.sh with below:

fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
fpath+=(${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/themes/pure)
source $ZSH/oh-my-zsh.sh
autoload -U promptinit; promptinit
prompt pure
Leave a Reply

Your email address will not be published. Required fields are marked *