Zsh and oh-my-zsh on Windows via Git Bash

Renan Alencar
5 min readDec 26, 2023

--

Setting up Zsh and oh-my-zsh on Windows via Git Bash

Set up Git on Windows

To set up Git Bash on Windows, follow these steps:

  1. Download the Git for Windows installer from the official website.
  2. Run the installer and select the desired components. Make sure the “Git Bash” option is selected.
  3. Follow the rest of the installer prompts to complete the installation.

Once Git Bash is installed, you can access it by right-clicking in a folder and selecting “Git Bash Here” from the context menu. This will open a Git Bash terminal window in that folder.

Set up Zsh on Git Bash

To set up Zsh on Git Bash, follow these steps:

  1. Download the latest Zsh package from the MSYS2 package repository. The file will be named something like “zsh-5.8–5-x86_64.pkg.tar.zst”.
  2. Install an extractor that can open TAR and ZST archives, such as 7-Zip and facebook/zstd (named something like “zstd-v1.5.2-win64.zip”). First, use zstd to extract the TAR file. Later, use 7-Zip to extract the files into the Git Bash directory.
# Open Git Bash
# Navigate to the zstd file
$ cd ~/../zstd-v1.5.4-win64
# Decompress the .zst file
$ ./zstd --decompress ~/Downloads/zsh-5.8-5-x86_64.pkg.tar.zst
# The TAR file will be created in the ~/Downloads/ directory
$ ls ~/Downloads/ | grep .tar
  1. Extract the archive’s files using 7-Zip (which should include etc and usr folders) into your Git Bash installation directory. This directory is usually located at "C:\Program Files\Git". If asked, merge the contents of the folder (no files should be overwritten).
  2. Open Git Bash and test Zsh.
# Testing Zsh
$ zsh

IMPORTANT: Configure tab completion and history in Zsh using the first-use wizard. If, for some reason, it doesn’t appear, or you skipped it, re-run it:

autoload -U zsh-newuser-install
zsh-newuser-install -f
  1. Configure Zsh as the default command-line shell.
# Create/edit the ~/.bashrc file
$ notepad ~/.bashrc
  1. Add the following content to the file:
if [ -t 1 ]; then
exec zsh
fi
  1. Save the file and close Git Bash.

Once Zsh is installed and set as the default shell, you can access it by opening Git Bash. Now, your Git Bash will open a Zsh terminal.

Set up oh-my-zsh

oh-my-zsh is a popular open-source framework for managing Zsh terminal. It includes a large number of plugins and themes, as well as a set of default configurations that can help you get started with Zsh. Using oh-my-zsh can help simplify and streamline your development, making it easier and more powerful than ever.

  1. To install oh-my-zsh, execute the following command in Git Bash:
# Install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Additional packages:

Set up a nerd font

You need to install a font that supports glyphs and symbols in the terminal. My favorite nerd font is the MesloLGS NF present in the powerlevel10k package and you can download it at this link. Another font that I really enjoy is the FiraCode font where you can download it here.

Set up a Color Theme Scheme

I fond of the Monokai theme for terminals. Below you find the scheme for the Monokai theme. Just copy the code into the schemes section in your Windows Terminal configuration file:

{
"background": "#0E0E0E",
"black": "#282828",
"blue": "#007EB4",
"brightBlack": "#6B6B6B",
"brightBlue": "#0383F5",
"brightCyan": "#8DDBF5",
"brightGreen": "#00FD7F",
"brightPurple": "#EF85D6",
"brightRed": "#F35B50",
"brightWhite": "#FFFFFF",
"brightYellow": "#FDC556",
"cursorColor": "#E4E4E4",
"cyan": "#50D0F9",
"foreground": "#E4E4E4",
"green": "#02C061",
"name": "Monokai zsh",
"purple": "#FF00C2",
"red": "#FF2B1C",
"selectionBackground": "#E4E4E4",
"white": "#CFCFCF",
"yellow": "#FBBC2E"
}

Set up Windows Terminal

  1. Download Windows Terminal by clicking here.
  2. Open Windows Terminal and run the following command below to generate an exclusive ID, which you will need to associate Git Bash with Windows Terminal.
[guid]::NewGuid()
  1. Open the flyout menu and click on Settings (or use the shortcut CTRL + “,”), then choose where you want to open the configuration file. You can use Notepad or another text editor of your choice. For instance, I am using Visual Studio Code.
  2. After opening the configuration file, add a new entry to the array list. Remember the GUID we created in step 2; we will use it to configure the Git Bash integration.
{
"colorScheme": "Monokai zsh",
"commandline": "C:\\Program Files\\Git\\bin\\bash.exe -i -l",
"font":
{
"face": "MesloLGS NF"
},
"guid": "{a805b8f4-b1b5-46d6-899b-73bbf34cca88}",
"hidden": false,
"icon": "C:\\Program Files\\Git\\mingw64\\share\\git\\git-for-windows.ico",
"name": "Git Bash",
"startingDirectory": "%USERPROFILE%"
}
  • GUID: The exclusive ID generated in step 2.
  • hidden: Keep this property as false to show up in the option list from the flyout menu.
  • name: The option name that will appear in the flyout menu.
  • commandline: The command used to open Git Bash via Windows Terminal. This command can be used even with cmd.
  • icon: Path to the Git Bash icon in case you want it to show up in the options from the flyout menu.

Note: Verify the paths in your operating system. The paths used in the commandline and icon properties are set according to my machine.

After applying these settings, a new option will appear in the flyout menu. By clicking on the Git Bash option, a new tab will open for you to work with Git Bash, or you can use the created shortcut, CTRL + Shift + 4.

One more tip: If you double-click on the tab title, you can change its name, making it easier to know what each tab is running.

References

#windowsterminal #gitbash #zsh #ohmyzsh #windows

--

--

Renan Alencar

Doctorate Student in Computer Engineering (Computer Intelligence). Data Scientist and Machine Learning Engineer. SR Software Developer.