Make your terminal look Swag with MSYS2 and ZSH
Tags: msys2, zsh, terminal, ohmyzsh
Published: 2020-11-19 13:24:56

> ### Yeah, I know, I know; you can use Bash on Ubuntu on Windows via WSL, but this article is specially for users using Windows 8.1 and below (and also for enterprise/LTSB Users)

Does your terminal look, boring, ugly and slow? Well, after reading this, your terminal will look like this:

![Demo](https://miro.medium.com/max/700/1*4sSVdfd_kU2zXYQak6ILPg.png)
###### Pretty cool, right?

## Let’s begin!
First things first, make sure you have:

* a good understanding of Computer Basics, _obviously_ ;)
* a good understanding of Terminal (Bash recommended) Basics, _again obviously_ :)
* a decent internet connection.

## Installing Cmder
First of all, head over to [this website](https://cmder.net) to download and install Cmder, a console emulator. You can install the _Mini_ version. No problems.

Open Cmder, you _must_ see this screen:

![Cmder first-install screen](https://dev-to-uploads.s3.amazonaws.com/i/2ptw3b4lmtepjw5ol54w.png)
###### This may look different, but the overall interface must be the same.

Let’s customize it, as it looks pitch black!

Press Win+Alt+P, to bring the settings option. Download the _MesloLGS NF_ font from [here](https://github.com/romkatv/powerlevel10k#manual-font-installation).

Click on the four files one by one; after it downloads, select the four _.ttf_ files, then right click, then _Install_. You _may_ need to provide the Administrator password for that.

After you install the _MesloLGS NF_ font, head over to General → Fonts in the left pane of Cmder Settings, and change the main console font and alternative font to _MesloLGS NF_. Change the font size to something larger, as the prompt looks like: _What is this? A prompt for ants?_ :) Ok, jokes apart. Your settings should look something like this:

![Cmder Settings](https://dev-to-uploads.s3.amazonaws.com/i/osvftu8wpk7ao3oieddv.png)

Optional: Head over to the Features → Colors tab and change the _Schemes_ option to \<Ubuntu\>. You can select whatever you like. If you didn’t like any of these, then head over to this [page] (https://github.com/joonro/ConEmu-Color-Themes#use-install-conemuthemeps1-powershell-script) and follow the instructions to install a theme you like. And wherever it says, _ConfigPath_, it means the path written near the Storage section above all the settings. Mine is C:\tools\Cmder\vendor\conemu-maximus5\ConEmu.xml. I personally prefer \<Ubuntu\>, provided with Cmder already.

After you do that, let’s install MSYS2.

## Installing MSYS2
First of all, download the installer (*.exe) from [this website](https://www.msys2.org/#installation) and follow the instructions there. It’s as simple as _Next_, _Next_ and _Install_ :)

After you install MSYS2, again open the settings of Cmder. Go to Startup → Tasks and click on _Add/Refresh default tasks_, and on the dialog box, click _Refresh default tasks_.

![Refresh default tasks](https://miro.medium.com/max/412/1*KJLmE7elZi2a39ou11LIhA.png)
###### Refresh default tasks

After you do that, you will see some _tasks_ in the _Predefined tasks_ panel. Click on the _{Bash::Msys2–64}_ task and click _Clone_ at the bottom. Then, click on the newly cloned task and at the white input box at the right, paste the following:

```batch
set CHERE_INVOKING=1 & set MSYSTEM=MINGW64 & set "PATH=%ConEmuDrive%\msys64\mingw64\bin;%ConEmuDrive%\msys64\usr\bin;%PATH%" & %ConEmuBaseDirShort%\conemu-msys2–64.exe -new_console:p %ConEmuDrive%\msys64\usr\bin\bash.exe -- login -ic "exec zsh" -new_console:C:"%ConEmuDrive%\msys64\msys2.ico"
```

![Change task options](https://dev-to-uploads.s3.amazonaws.com/i/bozreya4orz1t8wmbsdi.png)
###### Change task options.

What we’re basically doing is, we’re setting `CHERE_INVOKING` _env var_ to 1, which tells Bash to not `cd` into the HOME directory always. We’re also setting the `MSYSTEM` to `MINGW64` to use `Mingw` as the MSYS System instead of the Default MSYS, which is slower. Then, we’re setting the PATH variable to the `msys64\usr\bin` and `msys64\mingw64\bin` to use Windows-native binaries, `*.exe` to serve the purpose of basic Unix commands, like `clear` , `ls` , `rm` , and even utilities like `curl`. Coming to the PATH, we’re also setting the path to the Native Windows `%PATH%` variable. This helps to use the already-installed utilities like `node`, `kubectl`, `docker`, `npm`, etc. And we’re also invoking `conemu-msys2-64.exe` , which helps to _emulate the MSYS System_. Then, we’re passing `-new_console:p`, which starts a new Cmder/ConEmu Console Session. After that, we’re invoking our hero, `bash`, and setting it as a login shell. The `-c "exec zsh"` part should be kept for future, now remove that. Just keep `....exe --login -i` . After that, again some native Cmder commands.

> ### mic drop……………

So, after that, go to _Startup_ section (the parent one, neither the _Tasks_, nor _Environment_) and select the _Specified named task_ to the one we’ve just created/edited.

## Installing essential utilities
Let’s install some basic utilities:

```bash
pacman -S man vim nano tar
pacman -S openssh rsync make
pacman -S zip unzip
pacman -S mingw64/mingw-w64-x86_64-jq
```

Notice how easy it is to install things. For example, adding rsync to Windows is historically not easy at all — you end up going through various ports, forks, etc. This is much easier.

> #### Note about `sudo`: MSYS2 doesn't provide it. See [this question](https://superuser.com/questions/122418/theres-no-sudo-command-in-cygwin) or [imachug/win-sudo](https://github.com/imachug/win-sudo).

## Installing Git for Windows
If you had Git for Windows installed previously, uninstall it or just remove `C:\Program Files\Git\...`, or wherever you installed `Git`, from `$PATH`.

> #### [Reference](https://github.com/git-for-windows/git/wiki/Install-inside-MSYS2-proper)

1. Edit `/etc/pacman.conf` and just before `[mingw32]` , add the `git-for-windows` packages repository:
```
[git-for-windows]
Server = https://wingit.blob.core.windows.net/x86-64 
```
2. Authorize a signing key:
```
curl -L https://raw.githubusercontent.com/git-for-windows/build-extra/HEAD/git-for-windows-keyring/git-for-windows.gpg |
pacman-key --add - &&
pacman-key --lsign-key 3B6D86A1BA7701CD0F23AED888138B9E1A9F3986
```

3. Then, update/synchronise the repository with:
```
pacman -Syyuu
```
This updates `msys2-runtime` and therefore will ask you to close the window (not just exit the pacman process). Don't panic, simply close all currently open MSYS2 shells and MSYS2 programs. Double-check Task Manager and kill `pacman.exe` if it's still running after the window is closed, because it can linger. Once all are closed, start a new terminal again.

4. Then synchronize again (updating the non-core part of the packages):
```
pacman -Syuu
```

5. After that, install git and necessary things:
```
pacman -S git git-extras
pacman -S mingw-w64-x86_64-git-credential-manager mingw-w64-x86_64-git-lfs mingw-w64-x86_64-git-doc-man mingw-w64-x86_64-git-doc-html
```

6. Check that everything works by doing `git --version` and it should output something like `git version 2.14.1.windows.1` (or newer).

![Output for git --version.](https://dev-to-uploads.s3.amazonaws.com/i/olmn51v1om9hs8nb98qp.png)
###### Output for `git --version`.

## Installing ZSH
Finally, our _heroine_, ZSH! To install it, use:
```
pacman -S zsh
```

After that, run `clear` to clear everything up :)

Remember above, I told to keep `-c "exec zsh"` for future? Now the time comes. Add the `-c "exec zsh"` to the required place. Now, exit Cmder and open it again, you will get `zsh`! Yay!

It looks _cool_ at this point, but it still needs its _supporting actor_.

## Installing Oh-My-Zsh
Here’s our supporting actor, [Oh-My-Zsh](https://github.com/ohmyzsh/ohmyzsh), which helps us to theme our zsh to the one we’ve seen at the top!

So, first of all, run:
```
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

This installs oh-my-zsh. Done.

## Theme-ing Oh-My-Zsh
To achieve the result above, we need to install a theme called [Powerlevel10k](https://github.com/romkatv/powerlevel10k). Run:

```
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
```

Then, type `nano ~/.zshrc`. This opens `nano`, a text editor. Edit the line where it says, `ZSH_THEME="robbyrussell"` to `ZSH_THEME="powerlevel10k/powerlevel10k"`. Restart Cmder.

After that, it automatically runs `p10k configure`. This asks some questions, just follow whatever is told on the screen. To achieve the result above, use the Rainbow Prompt style. I recommend turning on _Instant Prompt_. You can read more about it [here](https://github.com/romkatv/powerlevel10k#instant-prompt). Also, you can turn on _Transient Prompt_. You can read more about it [here](https://github.com/romkatv/powerlevel10k#transient-prompt).

At this point, my `~/.zshrc` looks like this:

```
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# 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="/c/Users/AnotherUser.APPLE.000/.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="powerlevel10k/powerlevel10k"
# 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 the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=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.
# 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-autosuggestions zsh-syntax-highlighting)
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"
#source /usr/share/git/completion/git-completion.sh
#ZSH_THEME="powerlevel10k/powerlevel10k"
#parse_git_branch() {
 #git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
#}
#PROMPT_USER="\[\033[32m\]\u@\h\[\033[00m\]"
#PROMPT_DIR="\[\033[33m\]\w\[\033[00m\]"
#PROMPT_BRANCH="\[\033[35m\]\$(parse_git_branch)\[\033[00m\]"
#export PS1="$PROMPT_USER $PROMPT_DIR$PROMPT_BRANCH"$'\n$ '
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
```

Note that I’ve added two extra plugins (look for the `plugins=`... line), zsh-autosuggestions and zsh-autocomplete. You can copy this and paste this to nano editor while editing ~/.zshrc . But you do need to install them. To do that, run:

```
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
```

You can learn more about them [here](https://github.com/zsh-users/zsh-syntax-highlighting) and [here](https://github.com/zsh-users/zsh-autosuggestions)

After that, _restart your terminal_.

## Conclusion
Therefore, I conclude that, Windows users can also have a _Linux-y_ environment, the most powerful!
If you have any questions/suggestions, please write down below. And if I’ve made any mistake, please tell me. I’ll fix it ASAP.
Happy _hacking_!