Nirmal Lanka Hacker, engineer, artist, writer, musician. Hates Bit-coin. Conservative/republican.

(Updated: )

Cooler PowerShell prompt

Cooler PowerShell prompt

Like for bash or any other *ix shell, we can create profiles with shell configurations for PowerShell.

new-item -itemtype file -path $profile -force
notepad $PROFILE

Obviously, this opens the newly created profile item (at $profile) in Notepad. Just type and save! :simple_smile:

Cool prompt

function Prompt
    $id = 1
    $historyItem = Get-History -Count 1
       $id = $historyItem.Id + 1

    Write-Host -ForegroundColor Green -NoNewLine "$id "
    Write-Host -ForegroundColor Gray -NoNewLine "$(Get-Location) "
    $host.UI.RawUI.WindowTitle = "PS $(Get-Location)"

    "$ "

This creates a number-tagged prompt for re-using old commands with a simple dollar sign instead of the greater-than symbol that always confuses me… with a tiny bit of color.

I believe the code is quite self-explanatory, but if you find it to be confusing, let me know in the comments.

You’ll probably find my example prompt to be kinda boring, but you can see the possibilities and change stuff in the ways you find the coolest and more usefull.

Bonus: aliases and other stuff! :smile:

We can set the default starting directory:

set-location e:\dev

Add an alias:

new-item alias:np -value C:WindowsSystem32notepad.exe

Remove all stuff from the shell:


Change the shell colors:

$shell.BackgroundColor = “Gray”
$shell.ForegroundColor = “Black”

Set window size, buffer size:

$Shell = $Host.UI.RawUI
$size = $Shell.WindowSize
$Shell.WindowSize = $size
$size = $Shell.BufferSize
$Shell.BufferSize = $size

Why not share your awesome and useful profiles with us in the comments?! :wink:

(Updated: )

comments powered by Disqus