Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@huri3l

This comment has been minimized.

Copy link

@huri3l huri3l commented Dec 2, 2020

Is there a way to configure spaceship theme? I'm trying different solutions but the only theme that I was able to install was Honukai...

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Dec 2, 2020

Hi, I'm not sure, if that is just a normal zsh theme, you should be able to install that normally.
However, I think the spaceship has more stuff than just the theme, like the prompt, etc.
So, a quick look at their repo there and it seems that is not really working on Windows.
denysdovhan/spaceship-prompt#476

@wl2776

This comment has been minimized.

Copy link

@wl2776 wl2776 commented Dec 21, 2020

Hi! Thanks for a great advise.
However, it looks like I'm missing something.
Tab-completion doesn't work with Oh-My-Zsh

If I comment out line with source $ZSH/oh-my-zsh.sh then tab-completion works.

UPDATE: the solution is to add following two lines to etc\zshrc:

local drives=($(mount | command grep --perl-regexp '^\w: on /\w ' | cut --delimiter=' ' --fields=3))
zstyle ':completion:*' fake-files "/:${(j. .)drives//\//}"

Source:
Discussion: https://superuser.com/a/741343/755338
Gist: https://github.com/agross/dotfiles/blob/master/cygwin/completion.zsh#L4

@SiqingYu

This comment has been minimized.

Copy link

@SiqingYu SiqingYu commented Dec 24, 2020

This is helpful for Windows users who also want zsh experience. Thanks!.

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Dec 30, 2020

Hi! Thanks for a great advise.
However, it looks like I'm missing something.
Tab-completion doesn't work with Oh-My-Zsh

If I comment out line with source $ZSH/oh-my-zsh.sh then tab-completion works.

UPDATE: here is the solutiuon.
Discussion: https://superuser.com/a/741343/755338
Gist: https://github.com/agross/dotfiles/blob/master/cygwin/completion.zsh#L4

Cool. I didn't run into that problem yet, but it is nice to have a solution for it.

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Dec 30, 2020

This is helpful for Windows users who also want zsh experience. Thanks!.

:)

@dashengyeah

This comment has been minimized.

Copy link

@dashengyeah dashengyeah commented Jan 4, 2021

Hi! Thanks for a great advise.
However, it looks like I'm missing something.
Tab-completion doesn't work with Oh-My-Zsh

If I comment out line with source $ZSH/oh-my-zsh.sh then tab-completion works.

UPDATE: the solution is to add following two lines to etc\zshrc:

local drives=($(mount | command grep --perl-regexp '^\w: on /\w ' | cut --delimiter=' ' --fields=3))
zstyle ':completion:*' fake-files "/:${(j. .)drives//\//}"

Source:
Discussion: https://superuser.com/a/741343/755338
Gist: https://github.com/agross/dotfiles/blob/master/cygwin/completion.zsh#L4

Cool, It helps a lot!

@popstas

This comment has been minimized.

Copy link

@popstas popstas commented Jan 13, 2021

For me zsh was exited with code 127.
I have Git for Windows v2.16.4 (May 2018).

Update Git up to 2.30.0 solved problem.

@srikanth209

This comment has been minimized.

Copy link

@srikanth209 srikanth209 commented Jan 14, 2021

While extracting files to git dir, an error occurred. Access denied, cannot create an external directory. can anyone help me.

@popstas

This comment has been minimized.

Copy link

@popstas popstas commented Jan 14, 2021

@srikanth209, open preferences of Program files/Git, Security tab, add your user, grant Full access privileges.

@srikanth209

This comment has been minimized.

Copy link

@srikanth209 srikanth209 commented Jan 17, 2021

The latest package is not extracting the files to git.

@WrongxinYou

This comment has been minimized.

Copy link

@WrongxinYou WrongxinYou commented Jan 20, 2021

Thanks for the solution. As for me, I need to use zstd to extract the file. And compdef is not working when installing oh-my-zsh, so I redownload the plugins.

@Marcelo1197

This comment has been minimized.

Copy link

@Marcelo1197 Marcelo1197 commented Feb 6, 2021

Thanks for the solution. As for me, I need to use zstd to extract the file. And compdef is not working when installing oh-my-zsh, so I redownload the plugins.

I had the same problem and I found this: https://github.com/mcmilk/7-Zip-zstd/releases/tag/19.00-v1.4.8-R1
Now 7Zip support zstd files

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Feb 15, 2021

Hey all,

I've just installed it on a new machine here, so a few updates on the steps.

1) download the latest zsh package:

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

2) Extract the content to your git bash installation dir:

Same, just extracted to C:\Program Files\Git

3-4) Start and Config Zsh

  1. Test it, open git bash and type:
  2. If it start the zsh, it is working fine

So, these steps 3-4 are a bit important now, 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.
It took me a couple of minutes to understand and set the configs, but nothing really hard.

I think this part is what makes the tab completion problem to happen. I think that needs to get enabled here.

So, run:

zsh

And set the configurations properly.

5) Installing oh-my-zsh, execute the following cmd on git bash

Same, just run it:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

6) Configuring zsh as default shell

Edit the ~/.bashrc file.
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.

Same, in my case, that .bashrc didn't exist, so I've created it.

Optional steps

7) Installing the Honukay theme

Same, just run it:

curl -fsSL https://raw.githubusercontent.com/oskarkrawczyk/honukai-iterm/master/honukai.zsh-theme -o ~/.oh-my-zsh/custom/themes/honukai.zsh-theme

8) Set it

Same, just run it:

sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="honukai"/g' ~/.zshrc

--
No extra steps or configuration was needed.

@paalss

This comment has been minimized.

Copy link

@paalss paalss commented Feb 26, 2021

Hi,
I preferably don't want to install an additional software (the zsh-file extractor Peazip) just for installing zsh, so I'm wondering if this code is available in other shapes or forms.

Do you know if it's available on GitHub or as a normal zip file somewhere?

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Feb 26, 2021

Hi,

You can see the files/source info on the link:
https://packages.msys2.org/package/zsh?repo=msys&variant=x86_64

Btw, you can uninstall Peazip after extracting it.

@michelpfirter

This comment has been minimized.

Copy link

@michelpfirter michelpfirter commented Mar 5, 2021

Hi, unfortunately mi tab-completion is also broken on git-bash (mingw64) with oh-my-zsh. It works while using zsh only.

If I comment out line with source $ZSH/oh-my-zsh.sh then tab-completion works.

true for me

UPDATE: the solution is to add following two lines to etc\zshrc:

I do not have zshrc in
Programs\Git\etc
also creating the file and adding the lines below did not help.
Adding the files somewhere in
~/.zshrc
did not help either

local drives=($(mount | command grep --perl-regexp '^\w: on /\w ' | cut --delimiter=' ' --fields=3))
zstyle ':completion:*' fake-files "/:${(j. .)drives//\//}"

Source:
Discussion: https://superuser.com/a/741343/755338
Gist: https://github.com/agross/dotfiles/blob/master/cygwin/completion.zsh#L4

any help and hints are appreciated

SOLVED
I was able to solve my issue by adding a file in (and creating the completions directory)
$ZSH/completions/completion.zsh
containing the two lines mentioned above

local drives=($(mount | command grep --perl-regexp '^\w: on /\w ' | cut --delimiter=' ' --fields=3))
zstyle ':completion:*' fake-files "/:${(j. .)drives//\//}"

since oh-my-zsh.sh is looking there for completion files.

@jcisz

This comment has been minimized.

Copy link

@jcisz jcisz commented Mar 23, 2021

Hi, I fixed the autocomplete by deleting the .zcompdump in $HOME as commented here https://superuser.com/a/490392

I installed the spaceship following these steps denysdovhan/spaceship-prompt#476

  1. Cloned using git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
  2. Renamed spaceship.zsh-theme to ``spaceship.zsh-theme.old`
  3. Renamed spaceship.zsh to spaceship.zsh-theme
  4. Used ZSH_THEME="spaceship-prompt/spaceship instead of `ZSH_THEME="spaceship"
  5. Modified node.zsh to not use nvm current for the check.

a pull request is pending to be able to use nvm current coreybutler/nvm-windows/pull/569

@fworks

This comment has been minimized.

Copy link
Owner Author

@fworks fworks commented Mar 23, 2021

Great stuff @jcisz and @michelpfirter.
@huri3l please see this about the spaceship theme you wanted a couple of months ago.

@muhmwinchande

This comment has been minimized.

Copy link

@muhmwinchande muhmwinchande commented Apr 20, 2021

Worked like a charm for me, thanks @fworks

@XDeric

This comment has been minimized.

Copy link

@XDeric XDeric commented Apr 23, 2021

@fworks Hi, I downloaded the zsh package and extracted it to C:\Program Files\Git with pea zip. but it keeps saying I need to install zsh first. Not sure what to do at this point, thank you for any help you can provide.

git
gitbash2

@manciuszz

This comment has been minimized.

Copy link

@manciuszz manciuszz commented Apr 24, 2021

@fworks Hi, I downloaded the zsh package and extracted it to C:\Program Files\Git with pea zip. but it keeps saying I need to install zsh first. Not sure what to do at this point, thank you for any help you can provide.

The content you seek is inside zsh-5.8-5-x86_64.pkg.tar. If you check inside, you should notice that it contains 'etc' and 'usr' folders. Therefore, extract it again :)

@XDeric

This comment has been minimized.

Copy link

@XDeric XDeric commented Apr 24, 2021

@manciuszz Thanks that worked, but seems like I don't have chsh not sure how to manually change default shell.

zsh

@manciuszz

This comment has been minimized.

Copy link

@manciuszz manciuszz commented Apr 24, 2021

@manciuszz Thanks that worked, but seems like I don't have chsh not sure how to manually change default shell.

Refer to step 6) of https://gist.github.com/fworks/af4c896c9de47d827d4caa6fd7154b6b#gistcomment-3631820

@XDeric

This comment has been minimized.

Copy link

@XDeric XDeric commented Apr 24, 2021

Didn't change default to ohmyzsh I still have to switch to zsh everytime I open a new git bash terminal. not sure how to go to bashrc file and change it there

@XDeric

This comment has been minimized.

Copy link

@XDeric XDeric commented Apr 24, 2021

Nevermind, Weird I didnt have bashrc file had to create it using nano ~/.bashrc and paste it in there. also had to create the .bash_profile file too. Works well now just gotta change my theme. Thank you @manciuszz

@rescenic

This comment has been minimized.

Copy link

@rescenic rescenic commented Apr 24, 2021

Yeah, you need .bash_profile and .bashrc to get this to work.
.bash_profile

if [[ -f ~/.bashrc ]] ; then
	. ~/.bashrc
fi

Custom theme, like oh-my-zsh/powerlevel10k works too, just copy paste it from your cygwin/msys2 folder or use git clone the theme and plugins to custom folder.
omyzsh
Or if you want ready-made zip file of oh-my-zsh, extract it to your user profile folder. Download it here: https://www.mediafire.com/file/beqlomv07uw7ih8/.oh-my-zsh.zip/file

And dont forget to change the oh-my-zsh path in .zshrc file:
ohmyzsh

Or if you don't have .zshrc file yet, just copy paste it from here:
https://raw.githubusercontent.com/rescenic/dotfiles/master/.zshrc-windows
Change the username in oh-my-zsh path.

If it works the next time you open Git Bash, it will show you the preferences of powerlevel10k and create zcompdump file.

@XDeric

This comment has been minimized.

Copy link

@XDeric XDeric commented Apr 25, 2021

OH powerlink10k theme looks cool, Thank You @rescenic

@tomstark99

This comment has been minimized.

Copy link

@tomstark99 tomstark99 commented May 13, 2021

After I extract the files to \Program Files\Git I try

$ zsh

in a bash window and it doesn't do anything, it just prints a new line, like this

User@DESKTOP MINGW64 ~
$ zsh

User@DESKTOP MINGW64 ~
$ _

I extracted it just how the steps say, but it doesn't work. And if I set my bashrc up like you did, when I open a new bash window it closes immediately

@rescenic

This comment has been minimized.

Copy link

@rescenic rescenic commented May 13, 2021

@tomstark99, place extracted zsh files to: C:\Program Files\Git\usr\bin

@tomstark99

This comment has been minimized.

Copy link

@tomstark99 tomstark99 commented May 13, 2021

@tomstark99, place extracted zsh files to: C:\Program Files\Git\usr\bin

@rescenic I did that, it is still not working. My extracted files are in the correct place, but I cannot launch

$ zsh
@rhkdgns95

This comment has been minimized.

Copy link

@rhkdgns95 rhkdgns95 commented Jun 9, 2021

@tomstark99 Same symptoms as me.

@tomstark99

This comment has been minimized.

Copy link

@tomstark99 tomstark99 commented Jun 9, 2021

@rhkdgns95 I fixed it by updating my git

@rhkdgns95

This comment has been minimized.

Copy link

@rhkdgns95 rhkdgns95 commented Jun 9, 2021

@tomstark99

Can you tell me how you fixed it?

When I visit your github page, which repository can I check?

@chiragraman

This comment has been minimized.

Copy link

@chiragraman chiragraman commented Jun 11, 2021

I've tried putting the extracted files in various locations under C:\Program Files\Git but keep getting bash: zsh: command not found when I run zsh. I even tried updating git and it seems like I'm at the latest version Git for Windows 2.32.0.windows.1 (64-bit).

@tomstark99 could you please share the version you updated to ?
@rhkdgns95 any luck?

@rescenic

This comment has been minimized.

Copy link

@rescenic rescenic commented Jun 11, 2021

@chiragraman Paste /usr/bin/, /usr/share/, /usr/lib/ dan /etc/zsh/ folder from zsh 5.8 zst archive file to subfolder of your Git installation.

zshx

Here, I am using oh-my-zsh powerlevel10k theme.

@chiragraman

This comment has been minimized.

Copy link

@chiragraman chiragraman commented Jun 11, 2021

Seems like I had to run zsh.exe

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