How to Install Zsh and Oh My Zsh on Windows 10 (ok)

https://dominikrys.com/posts/zsh-in-git-bash-on-windows/

https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

C:\Users\lione.zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# 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 one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# 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.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# 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.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# 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?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
zsh-completions
zsh-syntax-highlighting
zsh-autosuggestions
composer
history
laravel
laravel4
laravel5
node
npm
wp-cli
yarn
yii
yii2
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# 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"

# 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"

Installing Zsh (and oh-my-zsh) in Windows Git Bash

November 11, 2021 · 3 min

Table of Contents

I’ve recently started using Windows again. After a long time using a customised Zsh shell on macOS and Linux though, I’ve started to miss some of the small productivity boosts that Zsh plugins offered me. Of course, I could set up the shell as I want it under WSL, but WSL doesn’t always play nicely with Windows-native applications and tools. To remedy this, I looked into how I could set up Zsh to run instead of Bash in Git Bash.

There are a couple of guides on GitHub from some years ago on how this can be achieved. However, I found they’re either outdated, or they don’t include information on whether plugins and custom themes can be used. I’ve addressed these issues in this post.

Installing Zsh in Git Bash

  1. Download the latest MSYS2 zsh package from the MSYS2 package repository. The file will be named something along the lines of zsh-5.8-5-x86_64.pkg.tar.zst.

  2. Install an extractor that can open ZST archives such as PeaZip or 7-Zip Beta.

  3. Extract the contents of the archive (which should include etc and usr folders) into your Git Bash installation directory. This is likely to be under C:\Program Files\Git. Merge the contents of the folder if asked (no files should be getting overridden).

  4. Open Git Bash and run:

    zsh
  5. IMPORTANT: configure the tab completion and history in the Zsh first use wizard. If for some reason it doesn’t appear, or you skip it, re-run it:

    autoload -U zsh-newuser-install
    zsh-newuser-install -f
    • To configure the history, press 1, change the values if you like by pressing 1-3, and then press 0.

    • To configure the completion, press 2 to “Use the new completion system”, and then press 0.

    • Press 0 to save the settings.

  6. Configure Zsh as the default shell by appending the following to your ~/.bashrc file:

    if [ -t 1 ]; then
      exec zsh
    fi

Installing oh-my-zsh

From this point, your Git Bash will behave essentially like a Unix Zsh shell. To install oh-my-zsh, run the usual command that you’d run in any Zsh shell:

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

Installing Plugins and Themes

To install plugins and themes, use their oh-my-zsh installation methods. I’ve installed the Powerlevel10k theme as well as the following plugins, and can verify that they work:

Fixing Mangled Output

Windows can mangle some UTF-8 encoded text, causing unexpected characters to be displayed in your terminal (more info in this Stack Overflow answer). To fix this, add the following to your ~/.bashrc file, ideally before code that sets your shell as Zsh:

/c/Windows/System32/chcp.com 65001 > /dev/null 2>&1

Troubleshooting

fworks’s guide tends to be fairly active, so it’s worth searching for or asking about any problems you may have there. Note that some of the information on there is outdated.

How to Install Zsh and Oh My Zsh on Windows 10

FEBRUARY 24TH, 2017

In this article I will tell how to make work with command prompt on Windows 10 better with Windows Subsystem for Linux, Hyper terminal, oh-my-zsh framework for zsh and zsh-syntax-highlighting plugin.

For this article you need to have Windows 10 x64 Version 1607 Build 14393 or higher and installed Node.js.

Install Windows Subsystem for Linux

If you have installed Windows 10 Build Less Than 16215:

First, you need to install Windows Subsystem for Linux. Go to Settings -> Update and Security -> For developers and change Sideload apps setting to Developer mode

Next open command prompt and go to OptionalFeatures.exe and enable Windows Subsystem for Linux (Beta) then reboot your PC. After rebooting you need to open command prompt and use bash command. Then begin automatic downloading and installation of Linux Subsystem.

In the next time when you need to use bash shell open command prompt and use bash command.

If you have installed Windows 10 Version 1709 (Fall Creators Update) Build 16215 or Higher:

Go to Settings -> Update and Security -> For developers and change Sideload apps setting to Developer mode.

Open command prompt and go to OptionalFeatures.exe and enable Windows Subsystem for Linux then reboot your PC.

Since Fall Creators Update we need to install Windows Subsystem for Linux from Windows Store.

For now (21 October 2017) we have three Linux distributions in Windows Store to choose from:

I recommend to install Ubuntu to this article.

Then after installing Ubuntu and rebooting PC you can run it with bash or ubuntu commands in command prompt.

In more detail, this parts is described in Installation Guide on the Microsoft Official Website.

Install Hyper Terminal

Go to official hyper terminal website and download latest version of terminal for Windows.

Install cURL and Git

Go to bash terminal installed above and use following commands:

  • Install cURL:

sudo apt-get install curl
  • Install Git:

sudo apt-add-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git

Install Zsh

To install Zsh use following command:

sudo apt-get install zsh

Install Oh My Zsh

Official GitHub repository of oh-my-zsh project https://github.com/robbyrussell/oh-my-zsh

To install oh-my-zsh go to bash terminal and use following command:

curl -L https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh | bash

and wait until the installation is completed.

Configure and Run Oh My Zsh

Now each time when you need to use bash shell and zsh you need go to command prompt, use bash (or ubuntu) command and then use zsh command.

Let’s simplify it.

If you have installed Windows 10 Build Less Than 16215:

Open bash terminal using bash command and use nano ~/.bashrc to open .bashrc config file.

Warning: Do not change Linux files using Windows apps and tools

In start of that file add following command:

bash -c zsh

Example: .bashrc file on gist

Note that in this time if you will try to use “default” command chsh -s /bin/zsh in bash shell terminal it will not run zsh as default bash shell environment.

Look at this comment of Ben Hillis @benhillis - https://github.com/Microsoft/BashOnWindows/issues/1724#issuecomment-282420193

Now each time when you will use bash in command prompt then zsh will start automatically instead of bash shell.

If you have installed Windows 10 Version 1709 (Fall Creators Update) Build 16215 or Higher:

Since Windows 10 Fall Creators Update you can run WSL with ubuntu command and chsh command will works.

https://github.com/Microsoft/BashOnWindows/issues/2199#issuecomment-334453644

So open ubuntu command in command prompt and use following command:

chsh -s /usr/bin/zsh

Each time when you will run ubuntu command then zsh will runs automatically as the default shell environment.

Note that this still will not work if you will run the bash command.

Configure and Run Hyper Terminal

If you have installed Windows 10 Build Less Than 16215:

After you installed Hyper Terminal open %USERPROFILE%/.hyper.js config file and replace line:

shell: '',

with

shell: 'C:\\Windows\\System32\\bash.exe',

Now each time when you will open hyper terminal it’s will be use zsh as default shell environment.

If you have installed Windows 10 Version 1709 (Fall Creators Update) Build 16215 or Higher:

After you installed Hyper Terminal open %USERPROFILE%/.hyper.js config file and replace lines:

shell: '',

and:

shellArgs: ['--login'],

with:

shell: 'C:\\Windows\\System32\\cmd.exe',

and:

shellArgs: ['--login', '-i', '/c wsl'],

respectively.

Short Q&A:

  • Question:

Why not just use path to ubuntu.exe file in hyper.is config?

  • Answer:

You can just use ubuntu.exe or full path to ubuntu.exe without any shell arguments:

shell: 'ubuntu.exe',
shellArgs: [],

or

shell: 'C:\Users\USERNAME\AppData\Local\Microsoft\WindowsApps\ubuntu.exe',
shellArgs: [],

but in this case your hyper terminal will opens only in Ubuntu home directory.

Links to related issues about this:

Solution: we can use cmd.exe in config and just run wsl as a command line argument. That’s works.

Also, note that in this case we are running wsl.exe not ubuntu.exe and this running Ubuntu because Ubuntu is current default “WSL OS”. For example if you will install openSUSE from Windows Store and set as default then wsl.exe will run openSUSE.

To understand what I mean, I recommend to reading article: Manage multiple Linux Distributions in WSL.

  • There is a second way to solve:

Also you can just use wsl.exe without any shell arguments:

shell: 'wsl.exe',
shellArgs: [],

And that’s works too.

Without installed themes for hyper this will looks like this:

Themes and other plugins for Hyper Terminal you can find here https://github.com/bnb/awesome-hyper.

I use hyper-material-theme theme by Mattia Astorino @equinusocio.

Change Oh My Zsh Theme

List of Oh My Zsh themes you can find here https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

By default oh-my-zsh use robbyrussell (like on screen above). If you want to change theme open ~/.zshrc config file by use following command in terminal:

nano ~/.zshrc

and change default “robbyrussell” value of ZSH_THEME variable to another theme name that you need to enable.

Known Issue: Hot key Ctrl + X in Hyper Terminal Does not Work. Instead of this use Shift + Ctrl + X. Link to Related GitHub Issue https://github.com/zeit/hyper/issues/1069

Known Issues for Windows Subsystem for Linux here https://github.com/Microsoft/BashOnWindows

Install zsh-syntax-highlighting plugin

Official GitHub repository of project https://github.com/zsh-users/zsh-syntax-highlighting

This plugin provides syntax highlighting in terminal like in Fish shell.

Open terminal and download zsh-syntax-highlighting plugin to .oh-my-zsh plugins directory using git:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

If $ZSH_CUSTOM variable exist and contains value (full path to /.oh-my-zsh/custom in this case) use its value, otherwise use ~/.oh-my-zsh/custom.

About :- (colon dash) you can read in this topic on stackoverflow: Usage of :- (colon dash) in bash.

Next to activate this plugin open ~/.zshrc config file using nano ~/.zshrc and find the following text:

# 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)

Here you need to add zsh-syntax-highlighting to plugins list. For that just replace

plugins=(git)

with

plugins=(git zsh-syntax-highlighting)

and save changes.

Finally you need to take changes into account. For that use follow command:

source ~/.zshrc

And now after restart hyper terminal you can see result. Screen:

Last updated