DEV Community

Cover image for Pursuit of happiness - oh my Windows terminal
Andres Lozada Mosto for Cloud(x);

Posted on

Pursuit of happiness - oh my Windows terminal

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

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:

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

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.

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



Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm


Enter fullscreen mode Exit fullscreen mode

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

Installing what we need



PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force
Install-Module oh-my-posh -Scope CurrentUser
Install-Module -AllowClobber Get-ChildItemColor


Enter fullscreen mode Exit fullscreen mode

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



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


Enter fullscreen mode Exit fullscreen mode

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



.\install.ps1


Enter fullscreen mode Exit fullscreen mode

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.



code $profile


Enter fullscreen mode Exit fullscreen mode

And add these lines to it



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


Enter fullscreen mode Exit fullscreen mode

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

Settings

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



…..   
"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
    }
    .....   


Enter fullscreen mode Exit fullscreen mode

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

Alt Text

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



sudo apt-get update
sudo apt-get upgrade


Enter fullscreen mode Exit fullscreen mode

Now we can install everything we need



sudo apt-get install git
sudo apt-get install zsh


Enter fullscreen mode Exit fullscreen mode

We make ZSH our default



chsh -s /bin/zsh


Enter fullscreen mode Exit fullscreen mode

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



if test -t 1; then
exec zsh
Fi


Enter fullscreen mode Exit fullscreen mode

Install Oh-My-Zsh



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


Enter fullscreen mode Exit fullscreen mode

We select the theme from the ./zshrc file.



code $HOME/.zshrc


Enter fullscreen mode Exit fullscreen mode

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



ZSH_THEME="norm"


Enter fullscreen mode Exit fullscreen mode

The last step is to install the plugin zsh-dircolors-solarized by cloning the repo



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


Enter fullscreen mode Exit fullscreen mode

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



plugins=(zsh-dircolors-solarized)


Enter fullscreen mode Exit fullscreen mode

Finally select the theme for the plugin



setupsolarized dircolors.ansi-dark


Enter fullscreen mode Exit fullscreen mode

The result…

Result


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!

🧉 + 🥐🥐 = Happy coder 💻

Top comments (5)

Collapse
 
plutonium239 profile image
plutonium239

"And not only on PowerShell, but on WSL and Azure Cloud Shell too!!"
Is there any way to do this for cmd(the classic <3 Command Prompt) as well?
I love using cmd over ps just because.

Collapse
 
andreslozadamosto profile image
Andres Lozada Mosto

Hi Samarth
No for the classic CMD there is no way to use something like this.

In windows 11 Microsoft will replace the default CMD by the Windows Terminal with Powershell... maybe is time to update the tool 😉

Collapse
 
plutonium239 profile image
plutonium239

Well thanks anyways!

Collapse
 
plutonium239 profile image
plutonium239

Just an update: clink can do this with a direct lua integration with oh my sh.
cmd ( > ps) ain't going nowhere!

Collapse
 
sowacx profile image
Michał Witczak

I guess it's windows 11 thing: There is no plain json settings when you open settings at terminal.

You can find at: $env:LocalAppData\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json