Skip to content

Instantly share code, notes, and snippets.

@harmandeep-singh
Last active August 25, 2022 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmandeep-singh/4fb1ae77e62babb9f29cd0489b04e720 to your computer and use it in GitHub Desktop.
Save harmandeep-singh/4fb1ae77e62babb9f29cd0489b04e720 to your computer and use it in GitHub Desktop.
Oh-my-zsh in Windows git bash

Oh-my-zsh in 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

7.1) Windows Terminal integration

  "C:\Program Files\Git\usr\bin\zsh.exe" -l -i

7.2) VsCode integration (open user settings.json)

{
    "terminal.integrated.profiles.windows": {
        "Git Zsh": {
          "path": "C:\\Program Files\\Git\\usr\\bin\\zsh.exe",
          "args": []
        }
      },
    "terminal.integrated.defaultProfile.windows": "Git Zsh",
 ...

7.3) install zsh-autosuggestions plugin type zsh in git bash and run this :

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH/plugins/zsh-autosuggestions
source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH/plugins/zsh-syntax-highlighting
source $ZSH/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

edit ~/.zshrc file

plugins=(... zsh-syntax-highlighting zsh-autosuggestions)

if you see wierd character when enabling auto-suggestion option on vscode and windows terminal

cd ~/.oh-my-zsh/plugins/zsh-autosuggestions
git checkout tags/v0.6.4 -b v0.6.4-branch
  1. see the ref. file
~/.zchrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="honukai"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
 DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# This will resolve Resize Crash issue for windows terminal and vscode 
unset LESS;
  1. C:\Program Files\Git\etc\zsh\zprofile
emulate sh -c 'source /etc/profile'
  1. C:\Program Files\Git\etc\zsh\zshenv
PATH=/mingw64/bin/usr/bin:/usr/bin:/bin:$PATH
# Default PROMPT
PROMPT="%F{green}%n@%m%f %F{magenta}${MSYSTEM}%f %F{yellow}%~%f %# "
export MSYS=enable_pcon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment