Skip to content

Instantly share code, notes, and snippets.

@DigitalMachinist
Last active November 7, 2020 17:51
Show Gist options
  • Save DigitalMachinist/4e09356197ca8049a2ada5ada315fb2e to your computer and use it in GitHub Desktop.
Save DigitalMachinist/4e09356197ca8049a2ada5ada315fb2e to your computer and use it in GitHub Desktop.
Finally a Decent Win10 Terminal

Finally a Decent Win10 Terminal

Written 2020-11-05

In this guide, my intent is to install a bash & zsh terminals onto a Windows 10 machine such that they:

  • Have easy access to the Windows filesystem
  • Run almost as fast as a native implementation
  • Have a good baseline vim config without additional work
  • Support copy/cut/paste with Ctrl+C, Ctrl+X, Ctrl+V like normal
  • Depend on only software that I have used and know works well
  • Support colour themes to liven up your terminal!

This process is based on Nuno Caneco's guide which references Sebastian Gingter's guide, plus a hack to make it all work under Windows Subsystem for Linux 2 (WSL2) that you can find here.

I'm also leaning on Microsoft's WSL install guide and it might be a valuable resource if you run into trouble.

Phase 1: Ubuntu for Windows Bash

  1. Open the Windows Store app.

  2. Install the Ubuntu app by Canonical Group Limited.

  3. Open a Powershell terminal as Administrator.

  4. Run the following command to install WSL:

    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  5. Run the following command to install VM features for WSL2:

    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  6. Reboot your computer. Yes, really.

  7. After rebooting, run the Ubuntu app to confirm that a bash terminal starts up. You may need to set a username & password for your Ubuntu user at this point.

  8. Run the following command at your Ubuntu bash terminal to create a symlink from your Ubuntu home (~) to your Windows user folder:

    ln -s ~/win10 /mnt/c/Users/<your Windows username>
  9. Congratulations! You have bash on Windows. But we're only getting started...

Phase 2: Cmder Bash

  1. Download the full version of Cmder (https://cmder.net/)

  2. Cmder is a portable app, so unzip it to any folder you want it to live in. I typically use C:\Users\<username>\.portable for my portable apps (so C:\Users\<username>\.portable\Cmder in this case). You'll probably also want to send a shortcut to Cmder.exe to your desktop or link to it in some other way for convenience. I always set this shortcut to "Run as Administrator" but I'm not sure this is required.

  3. Run Cmder and watch its default terminal work. We're going to ignore that from here on out. Click the green plus to open a new terminal and select {WSL::bash}. If you get an error like this, you need to follow step 4 (otherwise you can skip to step 5):

    wslbridge error: failed to start backend process
    note: backend error output: -v: -c: line 0: unexpected EOF while looking for matching `''
    -v: -c: line 1: syntax error: unexpected end of file
    
    ConEmuC: Root process was alive less than 10 sec, ExitCode=0.
    Press Enter or Esc to close console...
    
  4. If Cmder errors out on WSL Bash, you need to replace the wslbridge that failed in the error with wslbridge2. The Github issue comment where the following solution is invented is here if you want context. The solution goes like so:

    1. Recall the folder you unzipped Cmder to. Use explorer to navigate to <your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\ and rename cygwin1.dll to cygwin1-backup.dll. We're going to replace this file but keeping a backup never hurts.

    2. Download the latest release of wslbridge2 from https://github.com/Biswa96/wslbridge2/releases. I downloaded the x86_x64 version of release v0.7 but newer versions will probably work fine (famous last words?).

    3. Extract wslbridge2_cygwin_x86_64.zip to <your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\. Note that this creates a new cygwin1.dll that we're going to overwrite.

    4. Delete the newly extracted <your Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\cygwin1.dll. We don't need to back this up, but you can rename it instead if you're paranoid.

    5. Go to https://cygwin.com/snapshots/ and download the latest cygwin1-XXXXXXXX.dll.xz. I downloaded cygwin1-20200909.dll.xz but newer versions will probably work fine (famous last words?).

    6. Use 7-Zip to open your cygwin1-XXXXXXXX.dll.xz and extract it to <Cmder path>\vendor\conemu-maximus5\ConEmu\wsl\.

    7. Rename cygwin1-XXXXXXXX.dll to cygwin1.dll.

  5. In Cmder, press Win+Alt+T to open the Tasks Settings.

  6. Select the {WSL::bash} task and edit its command (the bottom text field) to the following:

    set "PATH=%ConEmuBaseDirShort%\wsl;%PATH%" & %ConEmuBaseDirShort%\conemu-cyg-64.exe %ConEmuBaseDirShort%\wsl\wslbridge2.exe - -cur_console:t:bash cur_console:pm:/mnt -eConEmuBuild -eConEmuPID -eConEmuServerPID -l -W ~/win10
  7. Exit the settings and open a new {WSL::bash} terminal again. It should open to a terminal without errors this time.

  8. Congratulations! You have a pretty solid bash with decent colouring and vim defaults for Windows. But we can go deeper...

Phase 3: Cmder + Oh My Zsh

  1. Open your new {WSL::bash} terminal in Cmder.

  2. Run the following command at your bash terminal to install zsh:

    sudo apt-get install zsh
  3. Edit your ~/.bashrc file (I use vim but using whatever *nix text editor you like) to include the following, right at the top of the file and save it:

    if test -t 1; then
        exec zsh
    fi
  4. Open a new {WSL::bash} terminal. You will be presented with the zsh setup wizard. I leave the details of this setup to you to figure out. It's your terminal!

  5. At this point, you should be sitting on a zsh terminal. To prove it, you can run ps and if zsh is one of the active processes then your golden!

    1. You may want to rename your {WSL::bash} terminal to {WSL::zsh} in Cmder.

    2. You can also replace cur_console:t:bash in the command string with cur_console:t:zsh so the terminal tab is named correctly in Cmder.

  6. Run the following command at your zsh terminal to install oh-my-zsh:

    sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  7. If you want to install a terminal theme, you can choose from the available options then edit the value of the ZSH_THEME variable in your ~/.zshrc to the name of your chosen theme. There are even more available options but you'll need to download these separately to use them. I like powerlevel10k myself, but this is an exercise for the reader.

  8. Congratulations! You might just have the nicest terminal that's ever been available on a Windows machine!

Finishing Touches

The instructions above cover the necessary steps to get zsh working and looking pretty, but there are some more things you might want to do to get the most out of this setup.

  • To make your WSL2 Ubuntu files more easily accessible from Windows, consider mapping \\wsl$\Ubuntu\ as a network drive. This will allow you to quickly and easily navigate to your Ubuntu root folder (/). Just type \\wsl$ into explorer, right-click on the Ubuntu folder, select Map network drive and pick your favourite letter for the drive.

  • Cmder's general settings include a colour theme of its own that interferes with the colours of oh-my-zsh themes. You might need to fuss with these to get the best look. I haven't figured out how to bypass this yet.

  • Definitely set up your {WSL::zsh} terminal as the default for new terminal windows in Cmder.

  • Consider installing a nice monospace font for your new terminal. Here are a few recommendations:

  • Consider upgrading your WSL2 Ubuntu from 20.04 to 20.10. It really does open up some exciting new possiblities for what you can do with it (like some of the recommended tools below).

  • Consider adding some other spicy *nix tools to your Windows terminal:

    • bat is a more colourful and usable version of cat
    • exa is a more colourful and usable version of ls
    • fd is a more colourful and usable version of find
    • httpie is a more colourful and usable version of curl
    • fzf is a powerful fuzzy-search tool. In particular, it supports keybinds such as Ctrl+R to fuzzy search your command history or Alt+C to fuzzy-find files recursively from your current folder.
  • I like to add the following lines to the end of my ~/.zshrc to automatically start up my SSH agent and install my SSH key so I can use Github without interruption:

    echo "Starting SSH agent..."
    eval $(ssh-agent -s)
    ssh-add ~/.ssh/<private key file>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment