Last active
July 7, 2018 01:47
-
-
Save bradwilson/0cf1818bc9dc6c203c68d44d2f96c102 to your computer and use it in GitHub Desktop.
Downloadable files for http://bradwilson.io/blog/anatomy-of-a-prompt
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
######## POSH-GIT | |
# ... Import-Module for posh-git here ... | |
# Background colors | |
$baseBackgroundColor = "DarkBlue" | |
$GitPromptSettings.AfterBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.AfterStashBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BeforeBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BeforeIndexBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BeforeStashBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchAheadStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchBehindAndAheadStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchBehindStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchGoneStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.BranchIdenticalStatusToBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.DelimBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.IndexBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.ErrorBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.LocalDefaultStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.LocalStagedStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.LocalWorkingStatusBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.StashBackgroundColor = $baseBackgroundColor | |
$GitPromptSettings.WorkingBackgroundColor = $baseBackgroundColor | |
# Foreground colors | |
$GitPromptSettings.AfterForegroundColor = "Blue" | |
$GitPromptSettings.BeforeForegroundColor = "Blue" | |
$GitPromptSettings.BranchForegroundColor = "Blue" | |
$GitPromptSettings.BranchGoneStatusForegroundColor = "Blue" | |
$GitPromptSettings.BranchIdenticalStatusToForegroundColor = "White" | |
$GitPromptSettings.DefaultForegroundColor = "Gray" | |
$GitPromptSettings.DelimForegroundColor = "Blue" | |
$GitPromptSettings.IndexForegroundColor = "Green" | |
$GitPromptSettings.WorkingForegroundColor = "Yellow" | |
# Prompt shape | |
$GitPromptSettings.AfterText = " " | |
$GitPromptSettings.BeforeText = " " | |
$GitPromptSettings.BranchAheadStatusSymbol = "" | |
$GitPromptSettings.BranchBehindStatusSymbol = "" | |
$GitPromptSettings.BranchBehindAndAheadStatusSymbol = "" | |
$GitPromptSettings.BranchGoneStatusSymbol = "" | |
$GitPromptSettings.BranchIdenticalStatusToSymbol = "" | |
$GitPromptSettings.DelimText = " ॥" | |
$GitPromptSettings.LocalStagedStatusSymbol = "" | |
$GitPromptSettings.LocalWorkingStatusSymbol = "" | |
$GitPromptSettings.ShowStatusWhenZero = $false | |
######## PROMPT | |
set-content Function:prompt { | |
$title = (get-location).Path.replace($home, "~") | |
$idx = $title.IndexOf("::") | |
if ($idx -gt -1) { $title = $title.Substring($idx + 2) } | |
$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$windowsPrincipal = new-object 'System.Security.Principal.WindowsPrincipal' $windowsIdentity | |
if ($windowsPrincipal.IsInRole("Administrators") -eq 1) { $color = "Red"; } | |
else { $color = "Green"; } | |
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor | |
if ($LASTEXITCODE -ne 0) { | |
write-host " " -NoNewLine | |
write-host " $LASTEXITCODE " -NoNewLine -BackgroundColor DarkRed -ForegroundColor Yellow | |
} | |
if ($PromptEnvironment -ne $null) { | |
write-host " " -NoNewLine | |
write-host $PromptEnvironment -NoNewLine -BackgroundColor DarkMagenta -ForegroundColor White | |
} | |
if (Get-GitStatus -ne $null) { | |
write-host " " -NoNewLine | |
Write-VcsStatus | |
} | |
$global:LASTEXITCODE = 0 | |
if ((get-location -stack).Count -gt 0) { | |
write-host " " -NoNewLine | |
write-host (("+" * ((get-location -stack).Count))) -NoNewLine -ForegroundColor Cyan | |
} | |
write-host " " -NoNewLine | |
write-host "PS>" -NoNewLine -ForegroundColor $color | |
$host.UI.RawUI.WindowTitle = $title | |
return " " | |
} |
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
# If the above settings don't work for Posh Git, try these instead: | |
# Background colors | |
$GitPromptSettings.AfterStash.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.AfterStatus.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BeforeIndex.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BeforeStash.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BeforeStatus.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchAheadStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchBehindAndAheadStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchBehindStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchColor.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchGoneStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.BranchIdenticalStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.DefaultColor.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.DelimStatus.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.ErrorColor.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.IndexColor.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.LocalDefaultStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.LocalStagedStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.LocalWorkingStatusSymbol.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.StashColor.BackgroundColor = "DarkBlue" | |
$GitPromptSettings.WorkingColor.BackgroundColor = "DarkBlue" | |
# Foreground colors | |
$GitPromptSettings.AfterStatus.ForegroundColor = "Blue" | |
$GitPromptSettings.BeforeStatus.ForegroundColor = "Blue" | |
$GitPromptSettings.BranchColor.ForegroundColor = "White" | |
$GitPromptSettings.BranchGoneStatusSymbol.ForegroundColor = "Blue" | |
$GitPromptSettings.DefaultColor.ForegroundColor = "Gray" | |
$GitPromptSettings.DelimStatus.ForegroundColor = "Blue" | |
$GitPromptSettings.IndexColor.ForegroundColor = "Green" | |
$GitPromptSettings.WorkingColor.ForegroundColor = "Yellow" | |
# Prompt shape | |
$GitPromptSettings.AfterStatus.Text = " " | |
$GitPromptSettings.BeforeStatus.Text = " " | |
$GitPromptSettings.BranchAheadStatusSymbol.Text = "" | |
$GitPromptSettings.BranchBehindStatusSymbol.Text = "" | |
$GitPromptSettings.BranchBehindAndAheadStatusSymbol.Text = "" | |
$GitPromptSettings.BranchIdenticalStatusSymbol.Text = "" | |
$GitPromptSettings.DelimStatus.Text = " ॥" | |
$GitPromptSettings.LocalStagedStatusSymbol.Text = "" | |
$GitPromptSettings.LocalWorkingStatusSymbol.Text = "" | |
$GitPromptSettings.EnableStashStatus = $false | |
$GitPromptSettings.ShowStatusWhenZero = $false |
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
param( | |
[switch]$noWebTools | |
) | |
if ($PromptEnvironment -ne $null) { | |
write-host "error: Prompt is already in a custom environment." -ForegroundColor Red | |
exit 1 | |
} | |
if (test-path Env:\VS140COMNTOOLS) { | |
$vsvars32 = [System.IO.Path]::GetFullPath((join-path (get-content Env:\VS140COMNTOOLS) "vsvars32.bat")) | |
if (test-path $vsvars32) { | |
write-host "Setting environment for Microsoft Visual Studio 2015." | |
$global:PromptEnvironment = " 2015 " | |
$tempFile = [IO.Path]::GetTempFileName() | |
cmd /c " `"$vsvars32`" && set > `"$tempFile`" " | |
Get-Content $tempFile | %{ | |
if ($_ -match "^(.*?)=(.*)$") { | |
Set-Content "env:\$($matches[1])" $matches[2] | |
} | |
} | |
Remove-Item $tempFile | |
if ($noWebTools -eq $false) { | |
$webTools = [System.IO.Path]::GetFullPath((join-path (get-content Env:\VS140COMNTOOLS) "..\IDE\Extensions\Microsoft\Web Tools\External")) | |
if (test-path $webTools) { | |
write-host "Adding Web Tools external tools to the PATH." | |
$env:path = $env:path + ";" + $webTools | |
} | |
} | |
} | |
else { | |
write-warning ("Cannot find " + $vsvars32) | |
} | |
} | |
else { | |
write-warning "Visual Studio 2015 is not installed." | |
} |
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
param( | |
[string]$edition, | |
[switch]$noWeb = $false | |
) | |
if ($PromptEnvironment -ne $null) { | |
write-host "error: Prompt is already in a custom environment." -ForegroundColor Red | |
exit 1 | |
} | |
# Try and find a version of Visual Studio in the expected location, since the VS150COMNTOOLS environment variable isn't there any more | |
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "2017" | |
if ((test-path $basePath) -eq $false) { | |
write-warning "Visual Studio 2017 is not installed." | |
exit 1 | |
} | |
if ($edition -eq "") { | |
$editions = (get-childitem $basePath | where-object { $_.PSIsContainer }) | |
if ($editions.Count -eq 0) { | |
write-warning "Visual Studio 2017 is not installed." | |
exit 1 | |
} | |
if ($editions.Count -gt 1) { | |
write-warning "Multiple editions of Visual Studio 2017 are installed. Please specify one of the editions ($($editions -join ', ')) with the -edition switch." | |
exit 1 | |
} | |
$edition = $editions[0] | |
} | |
$path = join-path (join-path (join-path $basePath $edition) "Common7") "Tools" | |
if ((test-path $path) -eq $false) { | |
write-warning "Visual Studion 2017 $edition could not be found." | |
exit 1 | |
} | |
$cmdPath = join-path $path "VsDevCmd.bat" | |
if ((test-path $cmdPath) -eq $false) { | |
write-warning "File not found: $cmdPath" | |
exit 1 | |
} | |
$tempFile = [IO.Path]::GetTempFileName() | |
cmd /c " `"$cmdPath`" && set > `"$tempFile`" " | |
Get-Content $tempFile | %{ | |
if ($_ -match "^(.*?)=(.*)$") { | |
Set-Content "env:\$($matches[1])" $matches[2] | |
} | |
} | |
Remove-Item $tempFile | |
if ($noWeb -eq $false) { | |
$path = join-path (join-path (join-path $basePath $edition) "Web") "External" | |
if (test-path $path) { | |
$env:path = $env:path + ";" + $path | |
} else { | |
write-warning "Path $path not found; specify -noWeb to skip searching for web tools" | |
} | |
} | |
$global:PromptEnvironment = " 2017 " |
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
param( | |
[string]$edition, | |
[switch]$noWeb = $false | |
) | |
if ($PromptEnvironment -ne $null) { | |
write-host "error: Prompt is already in a custom environment." -ForegroundColor Red | |
exit 1 | |
} | |
# Try and find a version of Visual Studio in the expected location, since the VS150COMNTOOLS environment variable isn't there any more | |
$basePath = join-path (join-path ${env:ProgramFiles(x86)} "Microsoft Visual Studio") "Preview" | |
if ((test-path $basePath) -eq $false) { | |
write-warning "Visual Studio Preview is not installed." | |
exit 1 | |
} | |
if ($edition -eq "") { | |
$editions = (get-childitem $basePath | where-object { $_.PSIsContainer }) | |
if ($editions.Count -eq 0) { | |
write-warning "Visual Studio Preview is not installed." | |
exit 1 | |
} | |
if ($editions.Count -gt 1) { | |
write-warning "Multiple editions of Visual Studio Preview are installed. Please specify one of the editions ($($editions -join ', ')) with the -edition switch." | |
exit 1 | |
} | |
$edition = $editions[0] | |
} | |
$path = join-path (join-path (join-path $basePath $edition) "Common7") "Tools" | |
if ((test-path $path) -eq $false) { | |
write-warning "Visual Studion Preview $edition could not be found." | |
exit 1 | |
} | |
$cmdPath = join-path $path "VsDevCmd.bat" | |
if ((test-path $cmdPath) -eq $false) { | |
write-warning "File not found: $cmdPath" | |
exit 1 | |
} | |
$tempFile = [IO.Path]::GetTempFileName() | |
cmd /c " `"$cmdPath`" && set > `"$tempFile`" " | |
Get-Content $tempFile | %{ | |
if ($_ -match "^(.*?)=(.*)$") { | |
Set-Content "env:\$($matches[1])" $matches[2] | |
} | |
} | |
Remove-Item $tempFile | |
if ($noWeb -eq $false) { | |
$path = join-path (join-path (join-path $basePath $edition) "Web") "External" | |
if (test-path $path) { | |
$env:path = $env:path + ";" + $path | |
} else { | |
write-warning "Path $path not found; specify -noWeb to skip searching for web tools" | |
} | |
} | |
$global:PromptEnvironment = " Preview " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment