Last active
December 24, 2022 00:48
-
-
Save cptpiepmatz/2fee8be91428cf4141e83ab1b64f43f5 to your computer and use it in GitHub Desktop.
My personal Prompt Style for Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ESC = [char]27 | |
switch ($env:ComputerName) { | |
"TIMSYOGA" {$computerName = "TY"} | |
"TIMSTOWER" {$computerName = "TT"} | |
default {$computerName = $env:ComputerName} | |
} | |
function ExitCode { | |
if (-not($?)) { | |
if ($LASTEXITCODE -ne 0) { | |
return " {" + $LASTEXITCODE + "}"; | |
} | |
} | |
return ""; | |
} | |
function OnBranch { | |
Try { | |
$consoleOut = $((git branch) -match "^\*\s+(?<Branch>\S+)"); | |
if ($consoleOut) { | |
if ($consoleOut -ne "True") { | |
$consoleOut = ($consoleOut -match "^\*\s+(?<Branch>\S+)"); | |
} | |
return " on " + "$ESC[38;5;163m" + $Matches.Branch + "$ESC[0m"; | |
} | |
} | |
Catch {} | |
return ""; | |
} | |
function ViaNode { | |
Try { | |
if (Get-Item -Path "package.json") { | |
$nodeVersion = $(node -v); | |
return " via $ESC[38;5;2mNode " + $nodeVersion + "$ESC[0m"; | |
} | |
return ""; | |
} | |
Catch { | |
return ""; | |
} | |
} | |
function ViaRust { | |
Try { | |
if (Get-Item -Path "Cargo.toml") { | |
$rustVersion = $((rustc -V) -match "rustc (?<Version>\S+)"); | |
return " via $ESC[38;5;166mRust " + $Matches.Version + "$ESC[0m"; | |
} | |
return ""; | |
} | |
Catch { | |
return ""; | |
} | |
} | |
function global:prompt { | |
"PS" + | |
"$ESC[38;5;1m" + | |
(ExitCode) + | |
" " + | |
"$ESC[38;5;33m" + | |
$env:UserName + | |
"@" + | |
$computerName + | |
"$ESC[0m" + | |
":" + | |
"$ESC[38;5;214m" + | |
("$pwd").Replace("$home", "~") + | |
"$ESC[0m" + | |
(OnBranch) + | |
(ViaNode) + | |
(ViaRust) + | |
"`n" + | |
"> " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment