Skip to content

Instantly share code, notes, and snippets.

@jonasnordlund
Last active February 13, 2022 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonasnordlund/8b52f8e09cbace35096e169244619f1d to your computer and use it in GitHub Desktop.
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.
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