Skip to content

Configure powershell with custom prompt and oh-my-posh

Notifications You must be signed in to change notification settings

tahmidul612/pwsh-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Setup Powershell

Powershell Preview

Install powershell preview with winget

winget install --id Microsoft.Powershell.Preview --source winget

Scoop is a package manager for Windows. It installs packages only for the current user (does not need admin privileges) and adds command line alias for the package when needed. The terminal does not have to be restarted to use the alias.

Run these commands in a non-elevated powershell/terminal (regular powershell without admin privileges)

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
iwr -useb get.scoop.sh | iex

Nerd Font

Install FiraCode Nerd Font with scoop

scoop bucket add nerd-fonts
scoop install FiraCode-NF-Mono

Update Default Shell

  • Restart terminal
  • Open terminal settings
  • Change Default profile from Windows Powershell to Powershell

You default profile may be different, change it to Powershell or Powershell Preview

Configure Terminal

  • Open terminal settings
  • Open JSON File
  • Copy and paste this Night Owl Theme into the schemes section
  • Navigate to the Powershell profile
  • Set the Starting Directory
  • Navigate to Powershell > Appearance
  • Set Color Scheme to Night Owl
  • Change Font Face to FiraCode Nerd Font Mono
  • Set Padding to 20 and Scrollbar Visibility to hidden

Set Background opacity to 90% and enable acrylic material (optional)

Open Appearance from the sidebar and turn on Use acrylic material in the tab row (optional)

Install oh-my-posh with winget

winget install JanDeDobbeleer.OhMyPosh -s winget

Restart terminal to enable oh-my-posh command alias

Disable oh-my-posh notices

oh-my-posh disable notice

Install and import PSReadline

Install-Module PSReadLine -AllowPrerelease -Force
Import-Module PSReadLine

Importing PSReadline is required to install psfzf

Install psfzf after installing fzf or the install/import may fail

Install fzf, psfzf, terminal-icons and gsudo

scoop bucket add extras
scoop install fzf terminal-icons
scoop install psfzf
scoop install gsudo

Install ZLocation

Install-Module ZLocation -Scope CurrentUser

Install scoop-search-multisource

For searching scoop directory waaaaay faster than the built in scoop search

scoop install "https://raw.githubusercontent.com/plicit/scoop-search-multisource/master/scoop-search-multisource.json"

Download and copy custom profile to Powershell profile directory

Profile is a modified version of https://thirty25.com/posts/2021/12/optimizing-your-powershell-load-times

iwr -uri "https://github.com/tahmidul612/pwsh-config/raw/master/profile.ps1" -outfile "$PROFILE"

Reload profile to enable the theme and modules

. $PROFILE

Optional Modifications

Disable daily update check

The provided profile has a function to check winget and scoop for updates once every day. This can be disabled by commenting out line 81 in the profile.ps1 file

Update check can be skipped by Ctrl+C, it will not check again that day

Windows Security Exclusion1

Security scans may be slowing down oh-my-posh, add oh-my-posh executable to Windows Defender exclusion list (or the exclusion list for you antivirus)

OMP Executable location

(Get-Command oh-my-posh).Source

Adding entire the scoop directory, or possibly just the modules directory to the exclusion list may also help

Scoop directory location

echo $env:USERPROFILE\scoop

Path Substitution Fix

Using $env:POSH_THEMES_PATH in the profile.ps1 file may cause a delay in loading the profile. This is a fix for that:

(Get-Content -Path $PROFILE).Replace('$env:POSH_THEMES_PATH', "$($env:POSH_THEMES_PATH)") | Set-Content $PROFILE

Replaces the environment variable with the absolute path

The terminal-icons module can take a while to load. This is a guide to modify the module to make it load 3x+ faster

Footnotes

  1. https://ohmyposh.dev/docs/faq#the-prompt-is-slow-delay-in-showing-the-prompt-between-commands

  2. https://github.com/devblackops/Terminal-Icons/issues/76

About

Configure powershell with custom prompt and oh-my-posh

Topics

Resources

Stars

Watchers

Forks