Skip to content

Instantly share code, notes, and snippets.

@kfsone
Created May 5, 2025 19:52
Show Gist options
  • Save kfsone/2e826226c9d2e4f1d37debfd8b30cdb9 to your computer and use it in GitHub Desktop.
Save kfsone/2e826226c9d2e4f1d37debfd8b30cdb9 to your computer and use it in GitHub Desktop.
Function Prompt {
# Status line has the current path and context.
$location = $executionContext.SessionState.Path.CurrentLocation
$branch = GetGitBranch
if ($branch)
{
if ($branch -eq 'master' -or $branch -eq 'main' -or $branch -eq 'Trunk')
{
$branchtext = "${BlueBg}:${branch}:${AnsiReset} "
}
else
{
$branchtext = "${MagBg}|${branch}|${AnsiReset} "
}
}
# visualization when you're on an additional input line,
# e.g. PS> if (test) {
# PS>> ...
$promptlevel = '>' * ($nestedPromptLevel + 1)
$time = "${GrayFg}$(Get-Date -DisplayHint Time)${AnsiReset}"
$kind = "PS"
if ($IsWindows) {
$kind = "Win|PS"
} elseif ($IsLinux) {
$kind = "Lin|PS"
} elseif ($IsMacOS) {
$kind = "Mac|PS"
} elseif ($PSEdition -Eq "Desktop") {
$kind = "MSW|PS"
}
# Return a string with status + prompt
"${GrayFg}[${time} ${branchtext}${location}${GrayFg}]${AnsiRest}`n${PromptFg}${kind}${AnsiReset}${Bold}${promptlevel}${AnsiReset} "
# See also:
# .Link# http://go.microsoft.com/fwlink/?LinkID=225750
# # .ExternalHelp System.Management.Automation.dll-help.xml
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment