Skip to content

Simon's Windows Terminal & VSCode PowerShell Profile

Notifications You must be signed in to change notification settings

smoonlee/oh-my-posh-profile

Repository files navigation

header-image

Oh-My-Posh :: Overview :: Mk3

terminal-preview

Important

#Requires -RunAsAdministrator
This script requires execution as Administrator, for Nerd Font Installation!

Release Notes

MAY 2024
Rebuilt Functions for Installation
Added custom PowerShell Functions - Get-PublicIP, Get-SystemUptime, Get-AzSystemUptime, Register-PSProfile, Update-WindowsApps, Remove-GitBranch
Added Support for AKS Clusters
Added Module Intellisense (Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete) Move PowerShell Modules back to User Documents
Rebuilt WSL/Linux bash script

Improvements Over Mk2

Since the release of the Mk2 Profile back in August 2023, I've learnt and realised that the PowerShell modules don't need to be installed directly in the C:\Program Files\WindowsPowerShell\Modules folder to get cross platform/version support. Having completed a lot of testing with some virtual machines, I worked out that you can use: C:\Users\%UserName%\Documents\PowerShell\Modules or C:\Users\%UserName%\Documents\WindowsPowerShell\Modules
By creating symbolic links between the two folder paths, you can import modules across both PowerShell versions.

While doing some research as well around $PROFILE tips and tricks, I found some super interesting links:

Chris Titus Tech - Pretty PowerShell
Scott Hanselman - My Ultimate PowerShell Prompt
Scott Hanselman - Customizing you Powershell prompt with PSReadLine
Anit Jha - Elevate your Windows PowerShell

Modules, Functions and Applications Overview

PowerShell Modules

Winget Modules

PowerShell Functions

[x] Azure CLI Tab Completion

Microsoft Docs Link: here

[x]> Get your current Public IP Address

Get-PublicIPAddress

[x]> Get Local System Uptime

Get-SystemUptime

Get-SystemUptime - Example

Hostname: XPS9510-SL
Uptime: 0 days, 4 hours, 6 minutes, 47 seconds
Last Reboot Time: 05/06/2024 10:10:32

[x]> Get Uptime of Virtual Machine in Azure

Get-AzSystemUptime -resourceGroup <resourceGroup> -vmName <vmName> -subscriptionId <subscriptionId>

Get-AzSystemUptime - Example (Windows)

[Azure] :: Getting System Uptime for windows01 in rg-bwc-sandbox-weu...
WARNING: This may take up to 35 seconds

[Azure] :: Hostname: windows01
[Azure] :: Uptime: 15 days, 4 hours, 25 minutes, 46 seconds
[Azure] :: Last Reboot Time: 06/05/2024 13:19:45

Get-AzSystemUptime - Example (Linux)

[Azure] :: Getting System Uptime for vm-learn-linux-weu in rg-learn-linux-weu...
WARNING: This may take up to 35 seconds

[Azure] :: Hostname: vm-learn-linux-weu
[Azure] :: Uptime: up 1 day, 1 hour, 54 minutes
[Azure] :: Last Reboot Time: 2024-05-05 11:27:17

[x]> Reload PowerShell Profile

Register-PSProfile

Register-PSProfile - Example

WARNING: Powershell Profile Reloaded!

[x]> Update Windows Applications (Using WinGet)

Update-WindowsApps

Update-WindowsApps - Examples

Updating Windows Applications...

Name            Id                 Version Available Source
-----------------------------------------------------------
Hugo (Extended) Hugo.Hugo.Extended 0.125.5 0.125.6   winget
1 upgrades available.

[x]> Remove-GitBranch (Singe Branch)

Remove-GitBranch -branchName <branchname>

Remove-GitBranch -branchName - Example

Deleted branch branch1 (was b7ef979).

[x]> Remove-GitBranch (All Branches)

This excludes 'main' and 'master' branches

Remove-GitBranch -all

Remove-GitBranch -all - Example

WARNING: This will remove all local branches in the repository!
Press any key to continue...

[Git] :: Moving to main branch
Switched to branch 'main'
Your branch and 'origin/main' have diverged,
and have 8 and 1 different commits each, respectively.
  (use "git pull" if you want to integrate the remote branch with yours)

[Git] :: Starting Branch Cleanse
Deleted branch branch1 (was b7ef979).
Deleted branch branch2 (was b7ef979).
Deleted branch branch3 (was b7ef979).
Deleted branch branch4 (was b7ef979).
Deleted branch branch5 (was b7ef979).

Windows Terminal Nerd Font

Nerd Fonts patches developer targeted fonts with a high number of glyphs (icons). Specifically to add a high number of extra glyphs from popular 'iconic fonts' You can get yours here: Nerd Font

Using the New-OhMyPoshProfile.ps1 it will auto install the Cascadia Code Font.
The font file which is installed is the: CaskaydiaCoveNerdFont-Regular.ttf
If you want to add this support to Visual Studio Code, you can update the Font Family:

'Consolas', 'Courier New', 'CaskaydiaCove Nerd Font'

Pre Device Setup

Important

If you've used the v2 setup, You'll manually need to remove Modules from
pwsh7 :: C:\Program Files\PowerShell\Modules
pwsh5 :: C:\Program Files\WindowsPowerShell\Modules

Powershell 5 default modules

Directory: C:\Program Files\WindowsPowerShell\Modules

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        07/05/2022     06:42                Microsoft.PowerShell.Operation.Validation
d-----        07/05/2022     06:42                PackageManagement
d-----        07/05/2022     06:42                Pester
d-----        07/05/2022     06:42                PowerShellGet
d-----        07/05/2022     06:42                PSReadLine

Profile Setup

-> Windows

New Device Setup
Ensure that you can execute scripts on your local machine
Set-ExecutionPolicy -Scope 'CurrentUser' -ExecutionPolicy 'RemoteSigned'

Download and execute the New-PSProfile.ps1 script.

$setupUrl = 'https://raw.githubusercontent.com/smoonlee/oh-my-posh-profile/main/New-OhMyPoshProfile.ps1'
Invoke-WebRequest -Uri $setupUrl -OutFile $Pwd\New-OhMyPoshProfile.ps1
.\New-OhMyPoshProfile.ps1

-> Linux

New Device Setup
setupUrl='https://raw.githubusercontent.com/smoonlee/oh-my-posh-profile/main/New-OhMyPoshProfile.sh'
curl -s $setupUrl -o $HOME/New-OhMyPoshProfile.sh ; bash New-OhMyPoshProfile.sh
WSL :: Kubernetes

NOTE
Since Mk3, This is built into the setup script!

You might need to create the .kube folder first.

mkdir $HOME/.kube

Then create a symbolic link to the Windows .kube folder.

NOTE
Please update the Users folder to match your Windows User folder

ln -sf /mnt/c/Users/<username>/.kube/config $HOME/.kube/config

About

Simon's Windows Terminal & VSCode PowerShell Profile

Resources

Stars

Watchers

Forks