Power Up Your Windows PowerShell

May. 30, 2024

I recently bought a new laptop which comes with Windows preinstalled on it, but I am an avid Linux user. I love the flexibility and freedom that Linux provides, and I have my fair bit of experience with various Linux distros, from Ubuntu, Zorin, Kali to Arch.

So my first thought after getting my new laptop was to switch to Arch, but I wanted to give Windows a try before switching. I heard a lot about Windows trying to make it better for developers by introducing various features like WSL, DEV HOME, etc. So, I have tried various Linux distros; why not give Windows a chance? For the past couple of months, I have been using Windows as my daily driver, and I have to say, they have improved a lot and introduced many features to impress developers.

And this is my experience: Linux is great, there is no doubt about that. The flexibility, customization, and freedom it offers are beyond what any other operating system will ever provide. But with Windows, we also have to fight a little with Microsoft to turn off all the unnecessary features and permissions, but it is possible to have a Linux-like experience in Windows with a little bit of effort. That’s what I do—I fight and figure it out.

In this blog, I am going to share how I customize my terminal in a way that is similar to the previous Linux setup that I have.

PowerShell

Windows does not use bash or zsh shells, although we can use these shells with WSL (that’s a topic for another blog). Now we are going to focus on customizing PowerShell.

Step 1: Installation

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop install sudo # similar to linux for admin access
sudo scoop install 7zip git openssh --global # utility tools
scoop install aria2 curl grep sed less touch neovim gcc # command line tools
scoop install nvm bun python java # dev tools and languages
Install-Module posh-git -Scope CurrentUser -Force
Install-Module Oh-my-posh -Scope CurrentUser -Force
Get-PoshThemes
Install-Module -Name Terminal-Icons -Repository PSGallery -Force
Install-Module -Name Z -Force
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
Install-Module -Name PsFzf -Scope CurrentUser -Force

It might be confusing what the heck these tools are, and I have intentionally not explained everything in this blog as that might be too long. I encourage you to explore each tool yourself. I have attached the link to those tools, and after this point, you might want to restart your computer.

Step 2: Customization

Change the Terminal Settings:

Step 3: Configuration

notepad $PROFILE.CurrentUserCurrentHost
# Prompt
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\wopian.omp.json" | Invoke-Expression

# Terminal Icons
Import-Module -Name Terminal-Icons

# PSReadLine
Set-PSReadLineOption -BellStyle None
Set-PSReadLinekeyHandler -Chord 'Ctrl+d' -Function DeleteChar
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle ListView

# Fzf
Import-Module PSFzf
Set-PSFzfOption -PSReadlineChordProvider 'Ctrl+f' -PSReadlineChordReverseHistory 'Ctrl+r'

# Alias
SET-Alias vim nvim
SET-Alias ll ls
SET-Alias g git
SET-Alias grep findstr
SET-Alias tig "C:\Program Files\Git\usr\bin\tig.exe"
SET-Alias less "C:\Program Files\Git\usr\bin\less.exe"
SET-Alias  c clear

# Utilities
function which ($command) {
    Get-Command -Name $command -ErrorAction SilentlyContinue |
      Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}

Tools References

Conclusion

Some might think that configuring and customizing is just a waste of time, but don’t let that stop you from configuring and customizing your system as you wish. It can save a whole bunch of time if you spend a little time understanding and configuring it. You can learn how computers work in the process of doing so, and plus, it’s FUN 😁.