Skip to content

Instantly share code, notes, and snippets.

@SunnyBingoMe
Last active December 12, 2018 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SunnyBingoMe/f991d99613451c2787d37f75a933e8d1 to your computer and use it in GitHub Desktop.
Save SunnyBingoMe/f991d99613451c2787d37f75a933e8d1 to your computer and use it in GitHub Desktop.
MS windows powershell promt, (without git)
# 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
@SunnyBingoMe
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment