Skip to content

Instantly share code, notes, and snippets.

@tree-s
Last active November 27, 2025 17:57
Show Gist options
  • Select an option

  • Save tree-s/d6bb5d6764ab95a65ee0cdb10c066508 to your computer and use it in GitHub Desktop.

Select an option

Save tree-s/d6bb5d6764ab95a65ee0cdb10c066508 to your computer and use it in GitHub Desktop.
PSReadline config
# --- Zsh-like PSReadLine Configuration for Windows PowerShell 5.1 ---
# Predictions (history-based)
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle Inline
# Use menu completion when pressing Tab (zsh-like)
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
# History search with Up/Down arrows (zsh substring search feel)
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
# Mild color scheme similar to zsh themes
Set-PSReadLineOption -Colors @{
Command = '#00afff'
Parameter = '#ffaf00'
String = '#a8ff60'
Operator = '#ff5f87'
Number = '#ffd700'
Comment = '#5faf5f'
InlinePrediction = '#606060'
}
# Huge history (zsh-like)
Set-PSReadLineOption -HistorySaveStyle SaveAtExit
Set-PSReadLineOption -MaximumHistoryCount 50000
# Optional: Simple zsh-like prompt (replace with oh-my-posh or starship if you want something fancy)
# Enable ANSI colors in Windows PowerShell
function Prompt {
# Capture last command status immediately
$lastStatus = if ($?) { "[ OK ]" } else { "[ ERROR ]" }
# Ensure console supports ANSI escapes (PS 5.1 doesn't always enable it)
if (-not ($Host.UI.SupportsVirtualTerminal)) {
$null = $Host.UI.RawUI | ForEach-Object {
$_.OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::new()
}
}
# ESC char
$esc = [char]27
# Colors
$green = "$esc[32m"
$red = "$esc[31m"
$cyan = "$esc[36m"
$blue = "$esc[34m"
$reset = "$esc[0m"
# Apply colors to status
if ($lastStatus -eq "[ OK ]") {
$status = "[ ${green}OK${reset} ]"
} else {
$status = "[ ${red}ERROR${reset} ]"
}
# user@host
$userhost = "${green}$env:USERNAME${reset}@${blue}$env:COMPUTERNAME${reset}:"
# Short path with ~ replacement
$pwd = $PWD.Path
if ($pwd -like "$HOME*") {
$loc = $pwd.Replace($HOME, "~")
} else {
$loc = Split-Path $pwd -Leaf
}
# Admin? -> #
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object Security.Principal.WindowsPrincipal($id)
$symbol = if ($p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { "#" } else { "$" }
# Final prompt line
"$status $userhost${cyan}${loc}${reset}$symbol "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment