Follow along to setup WSL and Z shell, an alternative to bash with awesome plugin and theme support. This setup uses the popular Oh My Zsh Zsh configuration framework to manage plugins and themes (it also comes bundled with a suite of aliases and helpers) and the impressive, Powerlevel10k Zsh theme.
- WSL and Ubuntu
- VS Code
- Windows Terminal
- Zsh and Oh My Zsh
- Powerlevel10k
- Install Zsh plugins
- Next steps
- Revert to bash
The following section details how to install WSL installing the latest LTS of Ubuntu.
-
Open Windows PowerShell as Administrator
-
Install WSL via:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Updating to WSL 2 is more involved. WSL 2 requires Windows Build 19041. For the time being, the most straight-forward method of updating to this build is to join Windows Insider.
To verify which Windows build you are running, open Settings and select System. Scroll to Windows specifications and note the value for OS build.
If you meet the requirements:
-
Enable the required feature:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
-
Restart your machine.
-
Open Windows PowerShell and run the command:
wsl --set-default-version 2
I skipped enabling WSL 2, and it hasn't issues as far as I can tell. I will likely revisit this once the build is distributed via Windows Update.
To install the latest Ubuntu LTS version (i.e. 20.04):
-
Open Windows Store and search for Ubuntu (quick link). Select Ubuntu (note you can verify the Ubuntu version by selecting More) and then select Install.
-
Launch Ubuntu to complete installation.
-
Create a user account by entering a User Name, i.e. your first name (typically lowercase) and a password.
See also: Change or recover your password
-
Update packages enter:
sudo apt update && sudo apt upgrade
Note you may need to right click or
ctrl+shift+v
to paste.Press
[enter]
to selectY
at the prompt to install any package updates.
We'll switch to Windows Terminal in a following step, as the default WSL/Ubuntu terminal emulator is not the greatest.
If you're a VS Code user some light setup is required for proper WSL use, namely installation of the Remote - WSL extension or the Remote Development extension pack.
Remote - WSL contains just the requirements for using WSL where as Remote Development contains a bundle of remote dev tools.
VS Code will prompt you to install Remote - WSL after it detects that WSL is installed. Alternatively, install either extension via the extensions tab in VS Code or with the Install button on the extensions' page.
See also: [VS Code:] Developing in WSL
This section details how to install and configure Windows Terminal.
To install Windows Terminal, open Windows Store. Search for and install Windows Terminal. I suggest pinning Windows Terminal to your start menu or taskbar.
The default profile shown when you launch Windows Terminal is Windows PowerShell. Selecting the dropdown reveals Ubuntu.
To change the default profile:
- Enter
ctrl+,
to open the settings file for Windows Terminal in you default editor. - Locate the
guid
for WSL/Ubuntu and then copy and paste this value in thedefaultProfile
property.
See settings.json in this repo for reference.
-
Include the following settings for
profiles.defaults
:"defaults": { // Put settings here that you want to apply to all profiles. "font": { // "face": "MesloLGS NF", "size": 9 }, "fontSize": 9, "snapOnInput": true, "historySize": 9001, "acrylicOpacity": 0.85, "useAcrylic": true, "closeOnExit": true },
Leave fontFace commented until you install the font in a following section.
-
Hide irrelevant profiles by setting the
hidden
property totrue
.
The following section details how to install Zsh and Oh My Zsh.
To install Z shell and set it as your default shell run:
sudo apt install zsh
chsh -s /bin/zsh
Log out and login back again to use your new default shell.
If you have no .zsh[...]
files in your home directory you will be prompted. Feel free to run through the configuration wizard however this will get replaced by Oh My Zsh. I recommend selecting 2
at the prompt to create a .zshrc
with defaults.
To install Oh My Zsh run:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
If you had a .zshrc
file it's now backed up as .zshrc.pre-oh-my-zsh
and replaced with a new configuration file which loads Oh My Zsh.
The following section outlines how to install the Powerlevel10k Zsh theme. The recommended font for p10k works well in Windows Terminal.
First, manually install the recommended Meslo Nerd Font (patched for p10k) - found here.
To install, download and double-click each variation and select install.
Note: If using Windows Terminal, enable the font by adding "fontFace": "MesloLGS NF"
to profile.defaults
or the WSL profile.
To install p10k:
- Run:
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
- Set
ZSH_THEME="powerlevel10k/powerlevel10k"
in~/.zshrc
.
Restart your shell by logging out logging back in. The configuration wizard should start automatically, otherwise run p10k configure
.
Follow prompts to configure p10k to your liking. First, it prompt you to verify whether you see given icons. Afterwards, you'll be prompted for ui preferences. These are up to you. The following choices work well but go crazy.
- Prompt Style: Rainbow
- Character Set: Unicode
- Show Current Time: 24-hour format
- Prompt Separators: Slanted
- Prompt Heads: Sharp
- Prompt Tails: Flat
- Prompt Height: Two Lines
- Prompt Connection: Solid
- Prompt Frame: Left
- Connection & Frame Color: Dark
- Prompt Spacing: Sparse
- Icons: Many Icons
- Prompt Flow: Concise
- Enable Transient Prompts: yes
- Instant Prompt Mode: Verbose
If you don't like what you came up with restart or remove your .p10k.zsh
file.
See p10k.zsh in this repo for reference.
The configuration I'm using at any given time is found in my deanbot/dotfiles repo.
- Edit
.p10k.zsh
- Uncomment the
battery # internal batter
line in the list ofPOWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
and save. - Run:
source ~/.p10k.zsh
to see changes.
Most plugins are installed automatically with Oh My Zsh by editting plugins
in .zshrc
.
The following suggested plugins have minimal installation steps:
To install zsh-autosuggestion and zsh-syntax-highlighting:
-
Run the following commands one at a time:
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
-
Permissions on these two plugins may be too permissive (you'll be warned by zsh the next time you log into your shell). To correct this run:
cd $ZSH_CUSTOM/plugins/ sudo chmod 755 ./zsh* cd ~
-
Edit
.zshrc
via your preferred editor be it nano, micro, VSCode, etc (i.e. for VSCodecode ~/.zshrc
). -
update the
plugins
line to:plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
and save.
Where to go from here? Some suggestions in no particular order:
- Review/adjust Windows Terminal keybindings.
- Extend dot files with your desired aliases or path modifications.
- Familiarize yourself with Zsh and browse tips & tricks from the community.
- View the Oh My Zsh cheatsheet.
- Explore the Oh My Zsh plugins directory.
- Customize p10k.
If you'd like to return from Zsh to bash this can be easily done:
- Uninstall Oh My Zsh (ref):
uninstall_oh_my_zsh
- Set default shell to bash:
chsh -s $(which bash)