Oh My ZSH! on Windows

Oh My ZSH! in Windows Subsystem for Linux

Steps:

  1. Install WSL
  2. Install zsh and Oh My ZSH!
  3. Install the new Windows Terminal
  4. Make Ubuntu default shell

Install WSL

The Windows Subsystem for Linux [WSL] lets developers run a GNU/Linux environment — including most command-line tools, utilities, and applications — directly on Windows, unmodified, without the overhead of a virtual machine.


More info about WSL: About the Windows Subsystem for Linux [docs.microsoft.com]

WSL is a full headless Linux (though you can install a xServer) inside Windows – no VM or the middleware Wine for Linux but a real Linux Kernel along/inside the Windows.

The installation instructions of WSL described by Microsoft are quite good, so I’ll simply Link the documentation:

Installation Guide for Windows 10

Install Zsh and Oh My ZSH!

Install the Z-Shell [zsh] and Oh My ZSH! in WSL as you know it from Linux / MacOS. Also configure oh-my-zsh e.g. change the theme (agnoster ftw!)

Window running Ubuntu in WSL with theme anoster

[Optional] Install pre-patched Powerline fonts on Windows

For some Oh My ZSH! themes like agnoster special fonts are required. You can either select one specific font or run the install script for Windows install.ps1 to install them all.

Powerline fonts: github.com/powerline/fonts

Install the new Windows Terminal

Somehow Microsoft thinks their new Terminal is that awesome, the created a ad / trailer or whatever this is.

This Terminal is currently (22.07.2019) a Preview, the Windows Terminal preview can be downloaded from the Microsoft Store.

Windows Terminal (Preview):
www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701 [Windows Store]

Make Ubuntu default shell

Make WSL default Shell

Now adjust the settings of Terminal. Currently when clicking on „Settings“ the config file profiles.json opens up. You need to set the value globals.defaultProfile to the guid of your WSL installation.

My config looks like this (as you can see, I also changed the styling of the Windows Terminal to the recommended „Solarized Dark colorscheme and Powerline-patched Meslo„):

{
    "globals" : 
    {
        "defaultProfile" : "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
        . . .
    },
    "profiles" : 
    [
        # Profile: cmd.exe,
        # Profile: Powershell,
        {
            "acrylicOpacity" : 0.5,
            "closeOnExit" : true,
            "colorScheme" : "Solarized Dark",
            "commandline" : "wsl.exe -d Ubuntu",
            "cursorColor" : "#FFFFFF",
            "cursorShape" : "bar",
            "fontFace" : "Meslo LG M for Powerline",
            "fontSize" : 12,
            "guid" : "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
            "historySize" : 9001,
            "icon" : "ms-appx:///ProfileIcons/{9acb9455-ca41-5af7-950f-6bca1bc9722f}.png",
            "name" : "Ubuntu",
            "padding" : "0, 0, 0, 0",
            "snapOnInput" : true,
            "useAcrylic" : false
        }
    ],

cd $HOME

When opening the Terminal it should run the Linux shell, but the working directory is the directory System32 of Windows. We should change this!

Therefore I added this to the end of the configuration of zsh in the file .zshrc:

# When coming from Windows, current dir is System32
# Change it to Linux $HOME
if [ $PWD = "/mnt/c/Windows/System32" ]
then
    # echo "This is Windows (@_@)  -->  cd to the user's home on Linux."
    cd ~
fi

Result:

The final result:
zsh with oh-my-zsh theme agnoster in WSL running inside the new Windows Terminal

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.