Skip to main content

PowerShell: Custom Prompts

Early on, I ran across a webcast about customizing your prompt. Being a child of 90s BBS door games, I love using characters for pictures. This of course led to the animation functions I made while practicing PowerShell, but it also led here.

Why settle for a vanilla prompt? I don’t normally work with the files of the location I’m in, so why should my prompt tell me every time it loads?

Prompt 1

My first version used ASCII emojis I grabbed from what’s available in Windows (press winkey + . ). They have different numbers of characters, so I set a 14-character-wide space, randomized what spot they’d end up in, and then filled the rest with placeholders. I just made an array of ~20 emojis that I liked, and it grabs a random one each time it loads. The left side of the emoji just shows the version of PowerShell I’m running.

Here’s the code. Just add it to your PowerShell profile.

Function Prompt {
$RandomColor = @(0..255)
$Art = @('( ノ ゚ー゚)ノ','ಠ,ಠ','(⊙_◎)','←_←','→_→','(x_x)','⊙.☉','¯\(°_o)/¯','(⊙_(⊙_⊙)_⊙)',"┗|`O'|┛",'w(゚Д゚)w','o((⊙_⊙))o','(¬‿¬)','( •_•)>⌐■-■','(⌐■_■)','(╯°o°)╯◠┻━┻','ಠ_ಠ','(•_•)') | Get-Random
If ($Art.length -lt 14) {
$ArtSpacersTotal = 14 - $Art.length
$ArtSpacersRight = ""
$ArtSpacersRightCount = Get-Random -minimum 0 -maximum $ArtSpacersTotal
For ($I = 0; $I -lt $ArtSpacersRightCount; $I++) {
$ArtSpacersRight = "┆",$ArtSpacersRight | Join-String
}
$ArtSpacersLeft = ""
For ($I = 0; $I -lt ($ArtSpacersTotal - $ArtSpacersRight.length); $I++) {
$ArtSpacersLeft = "┆",$ArtSpacersLeft | Join-String
}
$ArtSpaced = $ArtSpacersLeft,$Art,$ArtSpacersRight | Join-String
} Else {
$ArtSpaced = $Art
}
"`e[44mPS" + $PSVersionTable.psversion.tostring() + "`e[0m" + "`e[90m║`e[0m" + "`e[38;5;" + ($RandomColor | Get-Random) + "m" + $ArtSpaced + "`e[0m" + "`e[90m║`e[0m" + "`e[97m> `e[0m"
}

Later on, I found out that they added rich emoji support. I don’t typically use anything but ASCII characters, but I went ahead and designed a new prompt that makes use of those emojis that are available in Unicode. Again, I selected a small sample of them, and the prompt dynamically grabs a random one each time the prompt reloads.

Prompt 2

And here’s its code. It’s definitely the more elegant of the two.

Function Prompt {
$Art = @("`u{1F600}","`u{1F643}","`u{1F914}","`u{1F610}","`u{1F611}","`u{1F636}","`u{1F634}","`u{1F92E}","`u{1F976}","`u{1F92F}","`u{1F635}","`u{1F974}","`u{1F978}","`u{1F913}","`u{1F631}","`u{1F480}","`u{1F47B}","`u{1F47E}","`u{1F57A}","`u{1F93A}","`u{1F3C4}","`u{1F6A3}","`u{1F6C0}","`u{1F6CC}","`u{1F30B}","`u{1F4B0}") | Get-Random
"`e[44mPS" + $PSVersionTable.psversion.tostring() + "`e[0m" + "`e[90m║`e[0m" + $Art + "`e[90m║`e[0m" + "`e[97m> `e[0m"
}