Cygwin Oh My ZSH Recipe

This post documents my Cygwin + Oh My ZSH configuration which gives me a consistent cross platform terminal experience on Windows, OS X and Linux.

Web development workflow with git, node, npm, docker, vagrant, etc. is more comfortable when using the same familiar bash shell interface across different operating systems.

I don’t always use the command line in Windows - But when I do, I prefer Cygwin

Install Cygwin

Head over to Cygwin.com to get the setup file.

I used these settings with the Cygwin for 64-bit versions of Windows.

Cygwin Setup

  • Choose A Download Source: Install from Internet

  • Select Root Install Directory: C:\Cygwin Install For All Users

  • Select Local Package Directory: C:\Users\{UserName}\AppData\Local\Cygwin note: if your %userprofile% contains spaces, for example: C:\Users\Jared Dunn, this may cause issues.

  • Select Your Internet Connection: Direct Connection

  • Choose A Download Site: http://mirrors.xmission.com This mirror was reliable for me. They should generally all be up to date. It is recommended that you select a mirror site that is closest to you. Visit the Cygwin Mirror Sites page for more information.

  • Select Packages:

    • curl: Muti-protocol file transfer tool
    • fzf-zsh: fzf key bindings for Z shell
    • fzf-zsh-completion: fzf completion for Z shell
    • git: Distributed version control system
    • gitk: Git repository browser
    • zsh: The Z-Shell

Configure Cygwin Home Directory

Make your Cygwin home directory the same as your Windows User profile.

Edit the Cygwin /etc/nsswitch.conf file.

Add or edit the following line: db_home: /%H

more info: Stack Overflow – How can I change my Cygwin home folder after installation?

Install Oh My ZSH

Launch Cygwin and install Oh My ZSH using curl

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

You may find it necessary to manually install oh-my-zsh. Instructions are located in the source README at https://github.com/robbyrussell/oh-my-zsh#manual-installation

I received this output while Oh My ZSH install completed:

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc
Copying your current PATH and adding it to the end of ~/.zshrc for you.
I can't change your shell automatically because this system does not have chsh.
Please manually change your default shell to zsh!

Edit the Cygwin /etc/nsswitch.conf file.

Add or edit the following line: db_shell: /bin/zsh

More info: Stack Overflow - Set Default Shell in Cygwin

Mintty Configuration

This section documents some additional personalization preferences. Access the options by selecting the Cygwin application icon in the Title bar. For Looks, I have medium transparency selected.

Cygwin - Options - Looks
Options - Looks

For text, I have the Fira Code fonts installed on my system so have elected to use them and since my display is UHD, I am using the retina version. I have also set the font smoothing to full which is equivalent to subpixel anti-aliasing (“ClearType”).

Cygwin - Options - Text
Options - Text

Lastly, I wanted to add some spacing between the window borders and command text. I discovered that this could be done by editing the mintty configuration file in my home directory. I added the following line to the file, Padding=16. The entire configuration file is shown below.

~/.minttyrc
BoldAsFont=-1
Columns=96
Rows=48
Transparency=medium
Padding=16
Font=Fira Code Retina
FontWeight=450
FontSmoothing=full

Test drive using this handy cal 2017 command to display a calendar.

cal 2017

Other Useful Tips & Tricks

Windows Terminal

2020 Update - Add Cygwin to the Windows Terminal and benefit from it’s normalized keybindings and copy on select.

Set the default editor for git

# nano
git config --global core.editor C:/Cygwin/bin/nano.exe

# vi
git config --global core.editor C:/Cygwin/bin/vi.exe

Unsupported Bracketed Paste Mode

When pasting (Shift + Insert), if weird characters are wrapping the clipboard contents, disable bracketed paste mode in the .zshrc since the terminal doesn’t support escape sequences.

Unsupported ZLE Bracketed Paste
In this figure, unexpected characters ^[[200~ ~ are wrapping the pasted string.

~/.zshrc
if [[ $TERM = dumb ]]; then
    unset zle_bracketed_paste
fi

Resources

comments powered by Disqus