Last active
December 12, 2018 13:00
-
-
Save SunnyBingoMe/f991d99613451c2787d37f75a933e8d1 to your computer and use it in GitHub Desktop.
MS windows powershell promt, (without git)
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
# Import module from previous step | |
Import-Module -Name posh-git | |
function Test-Administrator { | |
$user = [Security.Principal.WindowsIdentity]::GetCurrent(); | |
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
} | |
function mklink { cmd /c mklink $args } | |
function prompt { | |
$realLASTEXITCODE = $LASTEXITCODE | |
Write-Host | |
# Reset color, which can be messed up by Enable-GitColors | |
#$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor | |
#$Host.UI.RawUI.BackgroundColor = "Black" | |
if (Test-Administrator) { # Use different username if elevated | |
Write-Host "(Elevated) " -NoNewline -ForegroundColor White | |
} | |
Write-Host "$ENV:USERNAME@" -NoNewline -ForegroundColor White -BackgroundColor DarkGreen | |
Write-Host "$ENV:COMPUTERNAME" -NoNewline -ForegroundColor White -BackgroundColor DarkGreen # -ForegroundColor Magenta | |
if ($s -ne $null) { # color for PSSessions | |
Write-Host " (`$s: " -NoNewline -ForegroundColor DarkGray | |
Write-Host "$($s.Name)" -NoNewline -ForegroundColor Yellow | |
Write-Host ") " -NoNewline -ForegroundColor DarkGray | |
} | |
Write-Host ":" -NoNewline -ForegroundColor DarkGray | |
Write-Host $($(Get-Location) -replace ($env:USERPROFILE).Replace('\','\\'), "~") -NoNewline -ForegroundColor Magenta | |
Write-Host " (" -NoNewline -ForegroundColor Gray | |
#Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta | |
Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor Gray | |
Write-Host ")" -NoNewline -ForegroundColor Gray | |
$global:LASTEXITCODE = $realLASTEXITCODE | |
Write-VcsStatus | |
Write-Host "" | |
return "> " | |
} | |
Set-Alias ls Get-ChildItemColor -option AllScope -Force | |
Set-Alias ll Get-ChildItemColor -option AllScope -Force | |
Set-Alias dir Get-ChildItemColor -option AllScope -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref: https://hodgkins.io/ultimate-powershell-prompt-and-git-setup