Install zsh in Windows 10 WSL, add grml's zsh configuration and make zsh start automatically.

Zsh is my favorite shell. Just to give one example of how awesome it is, here's how to list all files names containing bak recursively:

ls **/*bak*(.)

I used to run it in cygwin, but with Windows 10's WSL (Windows Subsistem for Linux) we can run Linux binaries natively.

  • Install WSL Ubuntu in Windows 10
  • Make sure it's up-to-date by running sudo apt update && sudo apt upgrade
Install zsh

Open a Bash on Ubuntu on Windows shell (start menu, type bash) and run:

sudo apt install zsh
Change the default shell to zsh

This is a bit tricky, because WSL starts from bash. Add the following code to the top of .bashrc in your home directory to switch to zsh when bash starts (vi ~/.bashrc):

case "$-" in
    *i*) export SHELL=`which zsh` && exec $SHELL -l && exit 0 ;;
    *) ;;

It will look like this:


I also changed the default shell for my username and root (to get a nice prompt after su):

sudo usermod -s /usr/bin/zsh root
sudo usermod -s /usr/bin/zsh [my_username]
Optional: get grml's zsh config files

I use grml live linux for system rescue, partitioning disks etc. It comes with a nice configuration for zsh. To install the grml config files, first we'll make a backup of the default zsh configuration in /etc/zsh/bak, then download the grml files from their repo into /etc/zsh. Modifying these files will require root permission (type password after sudo). Run these commands:

sudo su
cd /etc/zsh
mkdir bak
mv * bak/
.zshrc file

Here's a basic `.zshrc file that works well with the grml config:

# Set up prompt
autoload -Uz promptinit
prompt grml
zstyle ':prompt:grml:*:items:user' pre '%B%F{blue}'
zstyle ':prompt:grml:left:setup' items rc ofversion change-root user at host path percent

setopt histignorealldups sharehistory

# Use emacs keybindings even if our EDITOR is set to vi
bindkey -e

# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:

# Simplify LS_COLORS (no inverse background colors)
export LS_COLORS='rs=0:di=01;34:ln=35:so=32:pi=36:ex=01;33:bd=36;40:cd=34:su=36:sg=37:tw=01;34:ow=01;34:mi=01;31'

zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

# Use modern completion system
autoload -Uz compinit

export PATH="$PATH:$HOME/bin"

export EDITOR=vi

alias mmv='noglob zmv -W'
alias tlog='sudo tail -f /var/log/syslog'
alias scp='noglob scp'

Add a comment

Next Post