Skip to content

Instantly share code, notes, and snippets.

@SeanSobey
Last active September 30, 2020 07:28
Show Gist options
  • Save SeanSobey/f515ba6d0d0bd72d4bbc35b56a094341 to your computer and use it in GitHub Desktop.
Save SeanSobey/f515ba6d0d0bd72d4bbc35b56a094341 to your computer and use it in GitHub Desktop.
# https://joonro.github.io/blog/posts/powershell-customizations.html
# https://hodgkins.io/ultimate-powershell-prompt-and-git-setup
Import-Module posh-docker
Write-Host "Imported posh-docker"
# https://github.com/dahlbyk/posh-git
Import-Module posh-git
Write-Host "Imported posh-git"
$global:GitPromptSettings.BeforeText = '['
$global:GitPromptSettings.AfterText = '] '
$global:GitPromptSettings.EnableWindowTitle = ''
# https://github.com/lzybkr/PSReadLine
Import-Module PSReadLine
Write-Host "Imported PSReadLine"
Set-PSReadlineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadlineKeyHandler -Chord 'Shift+Tab' -Function Complete
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
# https://github.com/JannesMeyer/z.ps
Import-Module z
Set-Alias z Search-NavigationHistory -Scope Global
Write-Host "Imported z"
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
Write-Host "Imported Chocolatey Profile"
}
# Start-SshAgent
# Write-Host "Started SshAgent"
# http://serverfault.com/questions/95431
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function Prompt {
# https://github.com/dahlbyk/posh-git/wiki/Customizing-Your-PowerShell-Prompt
$origLastExitCode = $LastExitCode
$prompt = ""
$spacer = " " # " : "
$curPath = $ExecutionContext.SessionState.Path.CurrentLocation.Path
$prompt += Write-Prompt (Get-Date -Format G) -NoNewline -ForegroundColor DarkGreen # Date
$prompt += Write-Prompt $spacer -NoNewline -ForegroundColor DarkGray
if (Test-Administrator) { # if elevated
$prompt += Write-Prompt "(Elevated)" -NoNewline -ForegroundColor White
}
else {
$prompt += Write-Prompt "(Not-Elevated)" -NoNewline -ForegroundColor White
}
$prompt += Write-Prompt $spacer -NoNewline -ForegroundColor DarkGray
$prompt += Write-Prompt "$env:USERNAME@" -NoNewline -ForegroundColor DarkYellow
$prompt += Write-Prompt "$env:COMPUTERNAME" -NoNewline -ForegroundColor Magenta
$prompt += Write-Prompt $spacer -NoNewline -ForegroundColor DarkGray
$prompt += Write-VcsStatus # Posh-Git
$prompt += Write-Prompt $spacer -NoNewline -ForegroundColor DarkGray
# if ($curPath.ToLower().StartsWith($Home.ToLower())) {# Path
# $prompt += Write-Prompt "~" + $curPath.SubString($Home.Length) -NoNewline -ForegroundColor Blue
# } else {
$prompt += Write-Prompt $curPath -NoNewline -ForegroundColor Blue
# }
$prompt += "`n$('>' * ($nestedPromptLevel + 1)) "
$LastExitCode = $origLastExitCode
Update-NavigationHistory $pwd.Path
$prompt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment