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
  1. Extract the content to your git bash installation dir: Usually C:\Program Files\Git

  2. Test it, open git bash and type:

zsh
  1. If it start the zsh, it is working fine.

On some cases, there are stranger characters on the cmd line. It will get fixed when installing the oh-my-zsh

  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.

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.

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