Installing ZSH on Windows
Tags: zsh, windows, terminal, bash
Published: 2020-03-21 11:30:00

# Welcome Everyone

All of us have seen customizable and feature-full terminals in linux and mac, 
if you want to have a cool looking & powerful terminal in windows too, Follow me! 

Today I will be sharing how to install Z Shell with oh-my-zsh and also customizing it with an Awesome Theme and Plugins to bring a pimp to your terminal 

This is how the Final Setup will look like : 😎

![Preview](https://dev-to-uploads.s3.amazonaws.com/i/ak2l7b6xklcgfavt57tr.png)

This post is divided into 4 Parts

1. Setting Up Windows for ZSH installation (Cygwin & Cmder)
2. Installing Oh-my-zsh
3. Customizing Terminal and ZSH with Color Schemes & Themes
4. Some Extras to Refer to, Or some errors that might come.

You can refer to [My Github Repo](https://github.com/zinox9/zsh-windows), to get the files and skip this process , to get the same terminal as mine & to get some useful resources instantly too.

So Let's Begin 😋

---

# 1. Setting Up Windows

- For Windows we have to install

     a. **Cygwin** = Brings Unix environment in windows

     b. **Cmder** = One of the most Feature Full and customizable command prompt 

---  
### a. Cygwin Setup 


1. Download [Cygwin](https://cygwin.com/install.html)
2. When Running The Installer, Follow the Instructions. 
  1. Make Sure to Let the installer install at C:\cygwin64
  ![Cygwin Setup](https://dev-to-uploads.s3.amazonaws.com/i/21c2fvvp5mep5k92f63n.png)
  2. For Download site Select Any URL , Click Add
  3. **Stop** at packages screen, search **wget** expand **All** under **Web** select latest version of it under **bin** of **wget** no need to select Source. Then Continue. 
  ![Cygwin wget Screen](https://dev-to-uploads.s3.amazonaws.com/i/si0znxl4f9drhe8c0v44.png)
3. Finish Installing and launch the Terminal.  
4. We are going to use Cygwin to Install Some Packages that will help to use Linux System on Windows. We will install **apt-cyg** which will work like apt-get and also install many other packages too like vim
  - Run The following to download apt-cyg with wget. Note you can prompt to  install gdb, vim or dos2unix if you want to use them or just remove them, you can install even more packages of your choice if you wish !

```cmd
     > wget rawgit.com/transcode-open/apt-cyg/master/apt-cyg

     > install apt-cyg /bin

     > apt-cyg install zsh git gdb dos2unix openssh vim [or your favorite text editor]
```
   
- If you want your home folder to be your user's folder, you need to edit **cygwin64/etc/nsswitch.conf**.  You can do this in the text editor you just downloaded, or type `explorer /etc` to open the root directory to edit the file.
  - Add this line to the bottom: ```db_home: windows```

That's it for Cygwin , you can close the Terminal. Now let's move to the terminal we are using in this guide.

---

### b. CMDER setup

This Might Feel a lot, but just stick with me and I will guide you through every step 😊. 

In case you dont want to go through these , you can go to [My Github Repo](https://github.com/zinox9/zsh-windows) and just paste the specific files

![Cmder Preview](https://dev-to-uploads.s3.amazonaws.com/i/yfap1vqwkr4d0av2s28v.png)

1. Download and install one font from the package of [Powerline Font](https://github.com/powerline/fonts) to use in the terminal for the custom Icons. For This Guide I will be using **MesloGS NF** patched for powerlevel10k theme, you can find it in my github.

2. [Download Cmder](https://cmder.net/) (the full Version !) it's a portable package so to install it just extract it into a folder where it can stay permanently. (Don't Paste in Program Files)

3. Run cmder.exe

4. Right Click the Tab Bar and open Settings, We will be tweaking some of it. You can read and make changes as you wish 👍

    **i.** Under **General>Fonts.** = Select Main Console Font **MesloGS NF** and **remove check from Alternative Font**

    **ii.** Under **General>Size & Pos**. = Check Snap To desktop edges

    **iii.** Under **General>Appearance**. = 
      - You can remove Check from **Show Button In tab bar** and **Show Search Field**
      - Select **Hide Scroll Bar**

    **iv.** Under **General>Tab bar** select **auto show**.

    **v.** Under **General>Confirm** You can switch off confirmation of creating new tab if you don't need it (I Never wanted it).

    **vi.** Under **General>Taskbar** 
      - check **Don't show ConEmu Window on taskbar** & 
      - **Auto Minimize to TSA** (to not interrupt in alt+tab)

    **vii.** **IMPORTANT :**  Under **Startup>Tasks** 

    ![Cmder Settings](https://dev-to-uploads.s3.amazonaws.com/i/uxlcrtabi5ooblr9x1xu.png)

      <ul>
      <li>Click on <code>+</code> then Rename it from <code>Group xx</code> to 
      <code>cygwin:ZSH</code>. <ul>
      <li>Check <strong>Default Task For New Console</strong> </li>
      <li>Under Task you can give Location of any Icon You Wish to have (.ico file), I have given one nice icon in [my github](https://github.com/zinox9/zsh-windows) ```cmd 
-icon "C:\cygwin64\Cygwin.ico"
```
      </li>
      <li>Now In the Last Command Box paste this command```cmd
C:\cygwin64\bin\mintty.exe /usr/bin/zsh --login -i -new_console:d:%USERPROFILE%
```
      </li>
      <li>Last step is Click on **General** and choose startup task from the dropdown **{cygwin:ZSH}**</li>
      <li>Do the same for Admin Privileges , rename it as **{cygwin:ZSH as Admin}** and replace command with```cmd
*C:\cygwin64\bin\mintty.exe /usr/bin/zsh --login -i -new_console:d:%USERPROFILE%
```
      </li>
      </ul>
      </ul>

    **viii.** Under **Features>Colors** choose **Monokai** Scheme

    **ix.** For the setup of shortcuts, Click on **Keys & Macro** then change the shortcuts. Here is my setup :`
Win + Esc : Minimize/Restore
Win + Down : Create New Console
Win + T : Create new console (With Dialog)
Win + N : Split: Duplicate active ‘shell’ split to bottom
Win + Right : Switch Next Console 
Win + Left : Switch Previous Console
Win + Q : Close active Console
Win + E : Close all Consoles
Win + Alt + P : Show Settings 
Win + Alt + Space : Show ConEmu Menu`
      -  To make These Work go to **Keys & Macro>Keyboard** and check **Support Special Keys**

      **x.** Under **Keys & Macro>Paste** make sure Multi Lines is Checked Everywhere. 

      **Finally.**  After **Completing** the Settings Click On **Save Settings**.
 
5. You now Have setup to use Cygwin in Cmder, Close the terminal and open a new one 

6. Tada! you will see some differences, There You Go Running Cygwin In Cmder Successfully.

7. If a Prompt Comes type **0** to exit, we can edit the specified files later manually. 

---

# 2. Setting Up Oh-my-zsh

Now let's add a manager to handle plugins, updating and themes. It's Awesome that you have reached soo far, we are very close to completion. Great Work 🤘

- Install **oh-my-zsh** the manual way, Run the lines one by one 
```cmd
> git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
> cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
```
- Now Close the Terminal with shortcut (Win+q) or normal way, then open a new one
- If it prompts , type **0** to exit

![ZSH Installed](https://dev-to-uploads.s3.amazonaws.com/i/mbhn444x1pk6miynxsix.png)
##### There You Go Running ZSH on WINDOWS !

---

#### Now we are going to install an awesom theme and edit all features of zsh and cygwin you can continue if you wish to make it look like mine. 

You can also visit [My Github Repo](https://github.com/zinox9/zsh-windows) to instantly paste the files and you will be good to go ! 

---

# 3. Customizing Cygwin & Oh-my-zsh

  - <h3>Changing Color Scheme and other Mintty settings</h3>
    1. Right click your terminal 
    2. Hit options
    3. Change font-size and Apply the settings , this creates **.minttyrc** file
    4. Browse to Root folder of the user , open **.minttyrc** file and paste my settings, to change the color scheme to mine
```cmd
    BoldAsFont=no
    RightClickAction=paste
    Font=MesloLGS NF
    FontHeight=12
    Term=xterm-256color
    BoldAsColour=yes
    ConfirmExit=no
    Scrollbar=none
    Transparency=medium
    OpaqueWhenFocused=yes
    SelectionShowSize=1

    BackgroundColour=14,14,14
    ForegroundColour=228,228,228
    CursorColour=228,228,228
    Black=40,40,40
    BoldBlack=107,107,107
    Red=255,43,28
    BoldRed=243,91,80
    Green=2,192,97
    BoldGreen=0,253,127
    Yellow=251,188,46
    BoldYellow=253,197,86
    Blue=0,126,180
    BoldBlue=0,179,255
    Magenta=255,0,194
    BoldMagenta=239,133,214
    Cyan=87,208,249
    BoldCyan=141,219,245
    White=207,207,207
    BoldWhite=255,255,255
```

  - <h3>Changing Zsh Themes and prompts</h3>
    - To install the **Powerlevel10k** theme that I am using you can run
<pre><code>
     git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
</code></pre>
    - Set `ZSH_THEME="powerlevel10k/powerlevel10k"` in `~/.zshrc`.
    - Close and Open a new terminal window
    - Finally Go through the setup in the prompt as you wish
    - I have edited the **p10k.zsh** file, manually to make it look even more clear, the file is available in [My Github Repo](https://github.com/zinox9/zsh-windows) 😉
  
  ---
  - <h3>Adding Plugins</h3>
    - To install plugins just go to your root user folder, open `.zshrc` and you 
    will find a variable plugins. Simply add the plugins you want to install with 
    spaces `plugins=(git z zsh-autosuggestions)`
    - **Z** = saves the locations you visit the most, so that you can access it in one shot
    - **git** = brings many aliases in the command line
    - **npm Trash-cli** = it is an npm package, very useful to replace rm command
    - **Auto suggestions** = automatically suggests the code to type and autocomplete,  has to be installed manually not internally available 
      1. run `git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions`
      2. add `zsh-autosuggestions` in plugins variable

---
    
## SETUP COMPLETE 🎉

![Final Setup](https://dev-to-uploads.s3.amazonaws.com/i/eew9751y4hagz4obv9zj.png)


### There you go your Terminal has now become very powerful and awesome, it was great to share this with you all. Have Fun ! Keep Coding and Keep Exploring ! 🤘

--- 

## Extras

- You can checkout about all the features of oh-my-zsh on the internet , go explore
- Errors : 
  - on some commands oh-my-zsh ` runs less ` command with ` -R ` (repaint). You can disable this behavior by adding the following line **at the end** of your `~/.zshrc`

  ```cmd
    unset LESS;
  ```
  - This is set to `-R` in `~/.oh-my-zsh/lib/misc.zsh`

  - incase there is **Insecure completion-dependent directories** error : run this

  ```cmd
    chmod -R 755 ~/.oh-my-zsh
  ```