Skip to content

Instantly share code, notes, and snippets.

@cuckon
Created March 17, 2025 10:04
Show Gist options
  • Save cuckon/73f11402feb9a58939495074528152b8 to your computer and use it in GitHub Desktop.
Save cuckon/73f11402feb9a58939495074528152b8 to your computer and use it in GitHub Desktop.
Pretty Powershell Prompt
# Put it to $PROFILE
function prompt {
$path = Get-Location
$parts = $path.Path -split '\\'
# Extract drive letter and first folder
$drive = $parts[0]
$topFolder = if ($parts.Count -gt 1) { $parts[1] } else { "" }
# Render drive letter in orange
Write-Host "$drive\" -NoNewline -ForegroundColor DarkYellow
# Render top folder in blue if it starts with "Coding"
if ($topFolder -match "^Coding") {
Write-Host "$topFolder" -NoNewline -ForegroundColor Blue
} else {
Write-Host "$topFolder" -NoNewline
}
# Print remaining path
$lastFolder = $parts[-1]
if ($parts.Count -gt 3) {
Write-Host "\...\" -NoNewline
Write-Host "$lastFolder" -NoNewline
}
else {
Write-Host "\$lastFolder" -NoNewline
}
return " >"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment