Skip to content

Instantly share code, notes, and snippets.

@ryanhossain9797
Created April 28, 2026 02:42
Show Gist options
  • Select an option

  • Save ryanhossain9797/86776f18940467fdf2155333633f029e to your computer and use it in GitHub Desktop.

Select an option

Save ryanhossain9797/86776f18940467fdf2155333633f029e to your computer and use it in GitHub Desktop.
My Custom Prompt Powershell
function prompt {
# --- CONFIGURATION ---
$symbol_clean = "✔"
$symbol_dirty = "*"
$symbol_ahead = "↑"
$symbol_behind = "↓"
$symbol_stashed = "S"
# Define Colors
$color_user = "Green"
$color_path = "Blue"
$color_git = "Yellow"
$git_status_str = ""
# Check if we are inside a Git repository
$is_git = git rev-parse --is-inside-work-tree 2>$null
if ($is_git -eq "true") {
# Get current branch
$branch = git branch --show-current
# Get ahead/behind counts
$counts = git rev-list --left-right --count HEAD...@{u} 2>$null
$ahead = 0
$behind = 0
if ($counts -match "(\d+)\s+(\d+)") {
$ahead = $Matches[1]
$behind = $Matches[2]
}
# Check for dirty state (uncommitted changes)
$dirty_check = git status --porcelain
$dirty = if ($dirty_check) { " $symbol_dirty" } else { " $symbol_clean" }
# Check for stashed changes
$has_stash = git rev-parse --verify refs/stash 2>$null
$stashed = if ($has_stash) { " $symbol_stashed" } else { "" }
# Build ahead/behind string
$up_down = ""
if ($ahead -gt 0) { $up_down += " $symbol_ahead$ahead" }
if ($behind -gt 0) { $up_down += " $symbol_behind$behind" }
$git_status_str = " ($branch$up_down$dirty$stashed)"
}
# --- Render Prompt ---
# Line 1: user@host:path (git_status)
Write-Host "$($env:USERNAME)@$($env:COMPUTERNAME):" -ForegroundColor $color_user -NoNewline
Write-Host "$(Get-Location)" -ForegroundColor $color_path -NoNewline
Write-Host $git_status_str -ForegroundColor $color_git
# Line 2: The prompt symbol
return "❯ "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment