Skip to content

Instantly share code, notes, and snippets.

@fworks
Last active September 19, 2024 14:16
Show Gist options
  • Save fworks/af4c896c9de47d827d4caa6fd7154b6b to your computer and use it in GitHub Desktop.
Save fworks/af4c896c9de47d827d4caa6fd7154b6b to your computer and use it in GitHub Desktop.
Zsh / Oh-my-zsh on Windows Git Bash

Steps:

  1. Download the latest zsh package: https://packages.msys2.org/package/zsh?repo=msys&variant=x86_64

Example:

zsh-5.7.1-1-x86_64.pkg.tar.xz

Update:

The package now is compacted using zstd, so now we need some "special" extractor.
So, in my case, I've downloaded this file
https://repo.msys2.org/msys/x86_64/zsh-5.8-5-x86_64.pkg.tar.zst And extracted it using the Peazip.
https://peazip.github.io/zst-compressed-file-format.html

  1. Extract the content to your git bash installation dir:

Usually C:\Program Files\Git

  1. Test it and config zsh:

Open git bash and type:

zsh

So, this step is important, it seems zsh will ask a few configurations, like the tab completion, history, etc.
Please read the options and set that according to your use.

  1. Installing oh-my-zsh, execute the following cmd on git bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  1. Configuring zsh as default shell

Edit the ~/.bashrc file. (create it if it doesn't exist)

Add the following lines at the end of the file

# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi

Close and open again the git bash.

Optional steps

  1. Installing the Honukay theme
curl -fsSL https://raw.githubusercontent.com/oskarkrawczyk/honukai-iterm/master/honukai.zsh-theme -o ~/.oh-my-zsh/custom/themes/honukai.zsh-theme
  1. Set it
sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="honukai"/g' ~/.zshrc
@shierro
Copy link

shierro commented Apr 19, 2023

thanks! Looks good on Windows 11, good stuff

@kissingfire123
Copy link

kissingfire123 commented Jun 6, 2023

I noticed an issue with root directory autocompletion when I type for example "/c/use" and hit tab it won't find it, except in git bash I could get the autocompletion correctly and with capitalized folders like "/c/Users"

I ran into this problem also. inspired by @LionH , I founded a way to work around 🥇

#  after cd to c: , you will find you can complete by tab 
cd c:
cd Users/yourxxxPath  

the problem is zsh can't receive the sequences of windows-way. I tried stackoverflow: zsh-tab-completion-not-working and rehash-zsh guide, they didn't helped either.

@adamerose
Copy link

Putting this in .bashrc breaks anything trying to directly run bash commands.

if [ -t 1 ]; then
    exec zsh
fi

Didn't anyone else run into problems with VS Code because of this? I came looking for a fix but was surprised to see nobody mentioned it. For example VSCode runs npm scripts like "C:\Program Files\Git\bin\bash.exe '--login', '-i', '-c', 'npm run watch'", which doesn't work anymore.

Try to open cmd and run "C:\Program Files\Git\bin\bash.exe" --login -i -c "echo hello" and see it opens zsh but never echos anything.

Doing this instead seems to fix it:

# Check for BASH_EXECUTION_STRING to see if bash is being called with -c to execute a command.
if [[ -z "$BASH_EXECUTION_STRING" && -t 1 ]]; then
    exec zsh
fi

@rombat
Copy link

rombat commented Oct 12, 2023

image
any idea what could cause this issue when trying to install oh-my-zsh ?

@mamboer
Copy link

mamboer commented Oct 31, 2023

install zsh-autosuggestions plugin

  1. git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH/plugins/zsh-autosuggestions
  2. source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
  3. edit ~/.zshrc file
plugins=( 
    ...
    zsh-autosuggestions
)

install zsh-syntax-highlighting plugin

  1. git clone git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH/plugins/zsh-syntax-highlighting
  2. source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  3. edit ~/.zshrc file
plugins=( 
    ...
    zsh-syntax-highlighting
)

Cool. I will test that later. Thanks for that.

Change $ZSH to $ZSH_CUSTOM will be better.

@glenkusuma
Copy link

Install Git Bash with ZSH, OH MY ZSH & POWERLEVEL10K | Windows Guide

Thanks to all of you guys i've create a fork of fworks works and your guys' suggestion in the comment.

@MrOxMasTer
Copy link

image

guys, does anyone know how to remove this? What they write doesn't help. I tried using -f to run the function and it still appears

@teukureynld
Copy link

Screenshot 2024-04-03 183248

I've done writting the .bashrc, zsh wont showing up as git bash default theme. Can somebody help me?

@thesobercoder
Copy link

thesobercoder commented Aug 14, 2024

I cannot believe that I'm using Zsh on Windows. It works flawlessly. I didn't encounter most of the issues that others faced here except for ERROR: this script is obsolete, please see git-completion.zsh, and using OMZ on Windows is just the icing on cake. Wish somebody would create a Scoop installer to make the installation process easier alongside Git-bash.

@SteveDevOps
Copy link

This is awesome! Thx everyone.. added starship prompt to mine as well. Took steps here and moved init to .zshrc:
https://gist.github.com/SteveDevOps/b1f901dbc2128a378ff79d73ad3a59cc

Also running zsh in git bash as default shell within Tabby. Great for switching between git bash,
cmd, powershell, etc.

.. working!
gitbash-tabby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment