Last active
February 13, 2022 13:47
-
-
Save jonasnordlund/8b52f8e09cbace35096e169244619f1d to your computer and use it in GitHub Desktop.
My PowerShell Core profile. Random quote, green/red prompt depending on admin rights, cleaner path for Registry / UNC.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module Terminal-Icons | |
function prompt | |
{ | |
$identity = [Security.Principal.WindowsIdentity]::GetCurrent() | |
$principal = [Security.Principal.WindowsPrincipal] $identity | |
$adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator | |
$ESC = [char]27 | |
$promptColor = $principal.IsInRole($adminRole) ? "$ESC[91m" : "$ESC[92m" | |
"${promptColor}PS$ESC[0m $(Get-Location | Convert-Path)$('>' * ($nestedPromptLevel + 1)) " | |
} | |
function writeQuote($width) | |
{ | |
$docpath = [environment]::GetFolderPath('MyDocuments') | |
$quote = Get-Random -InputObject (Get-Content $docpath\PowerShell\quotes.txt | where {$_ -notlike '#*'}) | |
# Write-Host $quote -ForegroundColor Cyan | |
$words = $quote -split "\s+" | |
$col = 0 | |
foreach ( $word in $words ) | |
{ | |
$col += $word.Length + 1 | |
if ( $col -gt $width ) | |
{ | |
Write-Host "" | |
$col = $word.Length + 1 | |
} | |
Write-Host -NoNewline "$word " -Foreground Cyan | |
} | |
Write-Host "" | |
} | |
$PSVersionTable.OS | |
"PowerShell $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion)" | |
Write-Host "" | |
writeQuote(75) | |
Write-Host "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment