Using Zsh and zsh-autosuggestions on Windows Terminal with Oh My Posh theme

RMAG news

This article contains unstructions on how to configure Windows Terminal to use Oh My Posh with Zsh and zsh-autosuggestions.

This approach is not relying on WSL, it is utilizing existing Git installation on Windows. This way, you can have fully functional Zsh shell with autocomplete natively on Windows, just like you would on Mac.

Some people recommend using ble.sh – Bash Line Editor, a command line editor written in pure Bash which replaces the default GNU Readline (mentioned in Bash vs ZSH vs Fish: What’s the Difference?). However, on Windows I still prefer using Zsh with zsh-autosuggestions.

Configuration Instructions

Download and install Git from git-scm. Make sure to uncheck suggested options for Git Bash (e.g. the 2 options under “Windows Explorer integration”). You can select the option to add a Git Bash Profile to Windows Terminal, we will modify it manually later. When asked about adjusting your PATH environment, I like to use the Recommended setting, and I also like to enable symbolic links. I usually keep everything else on default settings.
From Microsoft Store, install Windows Terminal and winget App Installer. Check if everything has been installed properly by opening a new Windows Terminal session and typing winget –version.
Open your Windows Start menu, and search for “PowerShell”.

Run Windows PowerShell as Administrator, then install Oh My Posh using winget, for example:

winget install JanDeDobbeleer.OhMyPosh -s winget

Close PowerShell, then add oh-my-posh path to your Windows environment variables (User):

Press Win + r.
Type in control and hit ENTER.
Navigate to “User Accounts”.
Click on “User Accounts” one more time, then click the “Change my environment variables” link on the left side to open the “Environment Variables” window.
In the upper (User) part of the window, scroll down and select Path, then click the Edit… button.
Depending on the way your variables are displayed, either click New to add a new variable, or add a ; at the end of the line, then type in %LOCALAPPDATA%Programsoh-my-poshbin for the value. It might be that this value already exists, in which case you don’t need to edit anything.
Press OK and confirm every previously opened window by clicking OK.

Run PowerShell one more time with Administrator privileges, then install either the FiraCode Nerd Font or SauceCodePro Nerd Font (I prefer SourceCodePro) from Nerd Fonts using the following command (follow their instructions in order to select the desired font):

oh-my-posh font install

Open your Windows Start menu, search for “Terminal” and open it.

Click on the arrow next to the + button, then open a new Git Bash session.

Download the Zsh for Windows package zsh~x86_64.pkg.tar.zst:

curl -fsLo $HOME/zsh-5.9-2-x86_64.pkg.tar.zst https://mirror.msys2.org/msys/x86_64/zsh-5.9-2-x86_64.pkg.tar.zst

In Windows Explorer, locate the downloaded .zst file in your home directory and extract it either using:

PeaZip, which can be installed using the winget install -e peazip command, or

7-Zip (I prefer this option, since I already have it installed).

You only need the etc and usr directories, so copy these two directories from the extracted folder into C:Program FilesGit and when prompted, select the option to overwrite all existing files (don’t worry, these two zsh directories contain completely new files, no existing files will be overwritten).

Open %PROGRAMFILES%/Git/etc/profile.d/git-prompt.sh in your text editor (you might need Administrator privileges) and:

Comment out the GIT_EXEC_PATH=”$(git –exec-path 2>/dev/null)” line, then below it add a new line GIT_EXEC_PATH=”/c/Program Files/Git/mingw64/libexec/git-core”

Change the line that calls . $COMPLETION_PATH/git-completion.bash to call . $COMPLETION_PATH/git-completion.zsh.

OPTIONAL: I like to remove the PS1=”$PS1″‘n’ line that has # new line as a comment.

Open Windows Terminal’s settings using the Ctrl + Shift + , keyboard shortcut, then under the profiles > list array modify the existing Bash profile, or add a new profile:

{
“adjustIndistinguishableColors”: “always”,
“bellStyle”: “none”,
“colorScheme”: “VibrantInk”,
“commandline”: “%PROGRAMFILES%/git/usr/bin/zsh.exe -il”,
“font”:
{
“face”: “SauceCodePro NFM”
},
“guid”: “{12398ec4-4e3d-5e58-b989-0a998ec441b1}”,
“hidden”: false,
“icon”: “%USERPROFILE%/git.ico”,
“name”: “Git Bash”,
“opacity”: 70,
“startingDirectory”: “%USERPROFILE%”,
“useAcrylic”: true
}

The profile above uses a custom ~/git.ico icon, so you can use the default git-for-windows.ico icon file from C:Program FilesGitmingw64sharegit, or find another one you like.
If you wish, you can set the above profile to be your default Windows Terminal profile by setting the same guid as the defaultProfile value in the settings JSON.
Restart Windows Terminal and verify that everything is working (configure zsh using the interactive menu).
Install oh-my-zsh using the following command:

sh -c $(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)

Clone zsh-autosuggestions using the following command:

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

Open ~/.zshrc file, then dd the zsh-autosuggestions plugin to oh-my-zsh plugins:

plugins=(
git
zsh-autosuggestions
)

Save the changes and verify that autosuggestions are working (you need to have something in your history first, so type a couple of commands, exit the terminal with logout, then start the terminal again).

Grab the Gocilla theme for Oh My Posh and save the file under oh-my-posh themes:

curl -fsLo $HOME/AppData/Local/Programs/oh-my-posh/themes/gocilla.omp.json https://raw.githubusercontent.com/goranvasic/gocilla-oh-my-posh/main/gocilla.omp.json

Navigate to your Windows %USERPROFILE% directory, and open the .zshrc file one more time.

Add the following line below the source $ZSH/oh-my-zsh.sh line:

eval $(oh-my-posh init zsh –config $HOME/AppData/Local/Programs/oh-my-posh/themes/gocilla.omp.json)

Restart Windows Terminal and verify that everything is working properly.

That’s it. Hopefully this works on your side. Any comments or suggestions for improvement will be much appreciated.

You can find the latest version of these instructions on my GitHub repo here.