05 Jun

zsh and oh-my-zsh on Cygwin

I prefer to do things on the command line rather than click around on a UI (I type much faster than I can use a mouse). And I absolutely love the zsh and oh-my-zsh combination for my terminal. I mostly use a Mac (with iTerm2) and various flavours of Linux – all of which are really straight forward to set up. But sometimes I have to use Windows – and to keep to a Unix style shell (mostly because I know the commands much better), I use Cygwin as a shell when on Windows.

There are some instructions out there on getting zsh and oh-my-zsh set up on Cygwin, but I’ve always found that I need to combine a few of them to get the right setup, and I don’t do it often enough to remember. So I’m writing it down here – mostly for myself!

Cygwin setup

Start with a standard Cygwin installation – and I’m assuming you use the standard shortcut to start a shell that uses mintty.exe.

Use the standard Cygwin installer to install the latest versions of the following packages:

  • git
  • wget (or curl – you only need one of the two)
  • zsh

oh-my-zsh installation

  • Launch a Cygwin shell
  • Run the appropriate wget or curl command to download and install oh-my-zsh from the standard instructions.
    • With wget
      • sh -c "$(wget -O- https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
    • With curl
      • sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  • Exit the shell

Make zsh the default

You now have zsh and oh-my-zsh installed, but the default shell (when you double-click the icon) will still be bash (you need to execute zsh to change to it). Lets make zsh the default shell for your shortcut icon.

  • Right click the icon you use to launch Cygwin and select Properties.
  • In the Target field, change it to the following (replacing <cygwin-folder> with the actual folder where Cygwin is installed):
    • c:\<cygwin-folder>\bin\mintty.exe -i /Cygwin-Terminal.ico /usr/bin/zsh --login -
    • (The important bits where adding here is /usr/bin/zsh --login - if you miss the --login part the shell will misbehave and not find a lot of executables).
  • Try it out – if you now run a shell and execute echo $SHELL you should get back /bin/zsh

Customise oh-my-zsh

You can now customise zsh and oh-my-zsh as usual by modifying the contents of .zshrc in your (Cygwin) home directory. If you must know, I use either the agnoster theme, or a heavily customised version of powerlevel9k – they both have fantastic git support.

Powerline fonts

Some of these themes (and both that I mention above) require the Powerline fonts to be installed to get special characters.

  • In a Cygwin shell, in your home directory, execute git clone https://github.com/powerline/fonts.git --depth=1
  • Close the Cygwin shell.
  • Open Windows PowerShell as an Administrator (Window Key + X then select “Windows PowerShell (Admin)” and select “Yes”.) Change back to the directory where the “fonts” repository was downloaded (e.g. cd \<cygwin-dir>\home\<myuser>\fonts).
  • In the PowerShell, execute Set-ExecutionPolicy Bypass – accept the warning.
  • Execute .\install.ps1 – this will run the PowerShell script to install the fonts – it will take a while.
  • When done, reset your execution policy by executing Set-ExecutionPolicy Default and accept the warning.
  • You can now change the font in your mintty.exe setup to use a Powerline font.

This shows a screenshot with colour scheme “dracula”, transparency set to “Medium”, font “Noto Mono for Powerline” 9pt.