Pursuit of happiness - oh my Windows terminal
Published: 2020-09-21 15:03:21

What do you think if I tell you that your *PowerShell* can look like this? It's pretty right? 😍 🤩

![Windows Terminal + PowerShell Core looks great](https://dev-to-uploads.s3.amazonaws.com/i/grucyh6llc1k10amckwr.jpg)

After reading this post, you'll get this beautiful console that you'll love to work with. And not only on *PowerShell*, but on *WSL* and *Azure Cloud Shell* too!!  🥳 🤟

# Terminal alternatives
There are more options than the Windows Command Line (CMD) or Windows PowerShell. While they are mostly emulators that run on the terminal, they add good features and look better than the default consoles.

Alternatives over there:

- [CMDer](https://cmder.net/)
- [ConEmu](https://conemu.github.io/)
- [Windows Terminal](https://github.com/microsoft/terminal)
- [Hyper](https://hyper.is/)
- [Alacritty](https://github.com/alacritty/alacritty)
- [Terminator](https://medium.com/@bhupathy/install-terminator-on-windows-with-wsl-2826591d2156) (running over WSL)
- [Fluent Terminal](https://github.com/felixse/FluentTerminal) I just found it and looks great

I like to keep my dev environment simple so my choice is the new Windows Terminal using *PowerShell Core*. 

Why *Windows Terminal*? Microsoft listened to the community and created a totally brand new terminal which is really easy to use, have a lot of cool features like tabs, panes and it can run *PowerShell*, *CMD*, *Git bash*, *Linux bash*, *Azure Cloud Shell* as well as any other. 

The *Windows terminal* is relatively new. Previously I worked for many years with *ConEmu* and I can say that it is a very good option too

I encourage you to test all these alternatives and find which one fit best with you.

![Choose your best fit](https://dev-to-uploads.s3.amazonaws.com/i/z5b2haktir836gfds5sg.gif)

This article is based on *Windows Terminal*, but the configuration can be applied to the other tools as well.

# Installation

Let's see what we need to install to convert our boring terminal to an awesome one.
- [Posh-Git](https://github.com/dahlbyk/posh-git) (git extension)
- [Oh-My-Posh](https://github.com/JanDeDobbeleer/oh-my-posh) (themes)
- [Get-ChildItemColor](https://github.com/joonro/Get-ChildItemColor) (colorized sub-commands)
- [Power Fonts](https://github.com/powerline/fonts) (techie fonts)

Many of these should be installed using *PowerShell* with admin rights.

Well, let's start  💪 💻

## Changing the ExecutionPolicy 

> *NOTE:* this steps should be executed on *PowerShell* and *PowerShell Core* if you want to have the same theme on both.

So, we open the *PowerShell* as Admin and change the `ExecutionPolicy` to `RemoteSigned`

```bash
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm
```

When you are done, you can go back to the previous configuration by updating the `ExecutionPolicy` with scope `Process`.

## Installing what we need
```bash
PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
Install-Module oh-my-posh -Scope CurrentUser
Install-Module -AllowClobber Get-ChildItemColor
```

If you are using *PowerShell Core* you have to install `PSReadLine`.

```bash
Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck
```

To allow Power Fonts on our system we should clone the Github repository and run.

```bash
.\install.ps1
```

> *Tip:* the repo has a lot of fonts, so in my case I deleted all of them except the one called `Meslo Dotted`.

## Allowing all this stuff

In order to have all the modules installed every time we open the terminal, first we need to update our profile file.

```bash
code $profile
```

And add these lines to it

```bash
# Modules import
Import-Module posh-git
Import-Module oh-my-posh
Import-Module Get-ChildItemColor
​
# Theme to use
Set-Theme Agnoster
```

Now, we need to tell *Windows Terminal* to use our selected font. To do so, open the Settings file

![Settings](https://dev-to-uploads.s3.amazonaws.com/i/l5egjtsofp33qr5wun5t.jpg)

We search for the *"profile"* property and update it with the following.

```bash
…..   
"profiles": {
   "defaults": {
     "fontFace": "Meslo LG M DZ for Powerline",
     "fontSize": 8,
     "colorScheme" : "One Half Dark"
  },
   "list": [
    {
       // Make changes here to the powershell.exe profile
       "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
       "name": "Windows PowerShell",
       "commandline": "powershell.exe",
       "hidden": false
    }
    .....   
```

If you are using *ConEmu* o *CMDER* go to the `Settings Fonts` and select the Font previously installed.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cs1xs0rbm7vfymq7aoc0.jpg)

> *NOTE:* This changes will be reflected on the *Visual Studio Code Terminal* too 😉

***

# Extending this to WSL 

The magic of *WSL* is that we can use many flavours of Linux directly on Windows, removing any need of double-boot or *VMs*. Even so, its bash is still boring! so let's see how we can have the same here.

The natural option is to install PowerShell Core on the distro and set it as default bash, in order to follow the same steps as previously.

But, we are on Linux, where there are many alternatives and a good one is *ZSH*.

## Installation

First we'll update our Linux version

```bash
sudo apt-get update
sudo apt-get upgrade
```

Now we can install everything we need

```bash
sudo apt-get install git
sudo apt-get install zsh
```

We make *ZSH* our default

```bash
chsh -s /bin/zsh
```

Update the `.bashrc` file by adding this at the beginning of it.

```bash
if test -t 1; then
exec zsh
Fi
```

Install [Oh-My-Zsh](https://ohmyz.sh/)

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
```

We select the [theme](https://ohmyz.sh/) from the `./zshrc` file.

```bash
code $HOME/.zshrc
```

Search for “ZSH_THEME” property and change it for one you like

```bash
ZSH_THEME="norm"
```

The last step is to install the plugin [zsh-dircolors-solarized](https://github.com/joel-porquet/zsh-dircolors-solarized) by cloning the repo

```bash
git clone --recursive git://github.com/joel-porquet/zsh-dircolors-solarized $ZSH_CUSTOM/plugins/zsh-dircolors-solarized
```

Then go back to the `.zshrc` file and grant permissions to the pluging

```bash
plugins=(zsh-dircolors-solarized)
```

Finally select the theme for the plugin

```bash
setupsolarized dircolors.ansi-dark
```

The result…

![Result](https://dev-to-uploads.s3.amazonaws.com/i/rkeuql4ud5nuhs7obozo.JPG)

***

# Extending this to Azure Cloud Shell

I didn't try to set up all these things on *Azure Cloud Shell*, but it's based on Linux - so you can install ZSH and set it up as we did! Here it's explained (https://www.danielstechblog.io/setting-up-zsh-with-oh-my-zsh-in-azure-cloud-shell/)[https://www.danielstechblog.io/setting-up-zsh-with-oh-my-zsh-in-azure-cloud-shell/]



![Well done!](https://dev-to-uploads.s3.amazonaws.com/i/6wsps87yuia3kxofhyxj.JPG)



🧉 + 🥐🥐 = Happy coder 💻