Supercharge Your PowerShell: A Step-by-Step Guide to a Beautiful and Powerful Terminal

Ashish JhaAshish Jha
5 min read

Introduction

Are you tired of the bland, default PowerShell prompt? Do you dream of a terminal that's both visually appealing and highly functional? In this guide, I'll walk you through customizing your Windows Terminal and PowerShell to create a truly personalized and powerful command-line experience.

Getting Started: Windows Terminal and PowerShell Core

First, ensure you have the necessary tools:

Upgrade your Terminal/PowerShell fonts

A beautiful terminal starts with a great font, and Windows Terminal comes with a lovely font called Cascadia Code, a monospaced font from Microsoft designed for coding, but we will upgrade it to get more variant of this. Upgrading to the latest Cascadia Code release provides access to 'NF' (Nerd Fonts) variants, which include a wider range of glyphs and icons for enhanced terminal aesthetics.

  • Installing Cascadia Code Font

    1. Download the latest stable release of Cascadia Code Font from GitHub.

    2. Extract the downloaded archive.

    3. Navigate to the ttf folder.

    4. Select all the .ttf files at the root of the folder (not inside the static folder) and install them.

  • Updating the font in Windows Terminal

    1. Open Terminal

    2. Go to the Terminal Settings

    3. Profiles → Default

    4. Additional Settings → Appearance → Font Face

    5. Choose the Cascadia Code NF and save.

Adding Icons with Terminal-Icons

Let's add some visual flair by displaying icons for files and folders.

  • Open PowerShell (as administrator) and run:

      Install-Module -Name Terminal-Icons -Repository PSGallery
    

Next, add the Terminal-Icons module to your PowerShell profile.

  • Open your PowerShell profile with:

      notepad $profile
    
  • If the file doesn't exist, you can find the profile path using echo $profile and create the file manually.

  • Add the following line to your profile:

      Import-Module -Name Terminal-Icons
    
  • Save the file and either restart your terminal or reload your profile with .$profile.

Beautifying Your Prompt with Oh-My-Posh

Oh-My-Posh is a powerful theming engine for your terminal. Oh-My-Posh allows you to customize your prompt with various themes and segments, including information about your Git status, current directory, and more. Segments are small pieces of information that can be added to your prompt, like the current time, or the state of your git repository.

  • Install Oh-My-Posh using Winget (or your preferred method):

      winget install --id JanDeDobbeleer.OhMyPosh --source winget
    
  • Customize your prompt with a theme.

    • Oh-My-Posh offers a wide range of themes.

    • To use a theme, add the following line to your PowerShell profile, replacing jandedobbeleer.omp.json with your chosen theme:

        oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression
      
    • You can also create a custom theme by mixing and matching elements from different themes as well as adding any segments available for oh-my-posh.
      Customized theme which I use.

    • Remember to replace the theme name with the one you want to use.

Enhancing Command-Line Editing with PSReadLine

PSReadLine provides a rich command-line editing experience. PSReadLine enhances command-line editing with features like command history search, tab completion, and predictive IntelliSense.

  • PowerShell Core comes with PSReadLine pre-installed. If it's not present, install it with:

      Install-Module -Name PSReadLine -Repository PSGallery -Force
    
  • Add the following line to your PowerShell profile

      Import-Module PSReadLine
    
  • PSReadLine offers extensive customization options. Check out the documentation and sample profile.

  • This is the configuration which I use for PSReadLine

      Import-Module PSReadLine
    
      Set-PSReadLineOption -EditMode Windows
    
      # Searching for commands with up/down arrow is really handy.
      Set-PSReadLineOption -PredictionSource History
      Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
      Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
    
      # The option "moves to end" is useful if you want the cursor at the end
      # of the line while cycling through history like it does w/o searching,
      # without that option, the cursor will remain at the position it was
      # when you used up arrow, which can be useful if you forget the exact
      # string you started the search on.
      Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    
      # Instead of Inline suggestion (in grey) on search
      # if you like the suggestion in list which you can choose by up or down arrow
      # within the list, you can change the prediction view style
      Set-PSReadLineOption -PredictionViewStyle ListView
    
      Set-PSReadLineKeyHandler -Key Tab -Function Complete
    
  • Your final PowerShell profile may look like something like this:

      # Include Terminal Icons
      Import-Module -Name Terminal-Icons
    
      # Include oh-my-posh theme
      oh-my-posh init pwsh --config "C:\WindowsTerminal-Powershell\oh-my-posh-theme.json" | Invoke-Expression
    
      Import-Module PSReadLine
    
      Set-PSReadLineOption -EditMode Windows
    
      # Searching for commands with up/down arrow is really handy.
      Set-PSReadLineOption -PredictionSource History
      Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
      Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
    
      # The option "moves to end" is useful if you want the cursor at the end
      # of the line while cycling through history like it does w/o searching,
      # without that option, the cursor will remain at the position it was
      # when you used up arrow, which can be useful if you forget the exact
      # string you started the search on.
      Set-PSReadLineOption -HistorySearchCursorMovesToEnd
    
      # Instead of Inline suggestion (in grey) on search
      # if you like the suggestion in list which you can choose by up or down arrow
      # within the list, you can change the prediction view style
      Set-PSReadLineOption -PredictionViewStyle ListView
    
      Set-PSReadLineKeyHandler -Key Tab -Function Complete
    

0
Subscribe to my newsletter

Read articles from Ashish Jha directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ashish Jha
Ashish Jha

I'm an enthusiastic Software Developer with over 7 years of experience, specializing in backend development. Tech stack includes .NET, C#, SQL, Azure, Kubernetes, Microservices architecture, and a knack for working with Transactional Databases like MSSQL and MySQL, as well as Analytics Databases like Vertica. 🚀 Currently, I'm a Staff Engineer at the dynamic startup, CareStack, where I contribute to building innovative solutions. 📚 Beyond coding, I'm an avid enthusiast of Core Computer Science topics, including Networking, Databases, and Operating Systems. Thrive on the challenge of performance optimization and believe that there's always room for improvement in every line of code. Join me on this journey as we explore the ever-evolving world of software development and technology! Let's code, learn, and grow together! 🌟