Instantly share code, notes, and snippets.

Embed
What would you like to do?
Personal posh-git PowerShell profile (https://dahlbyk.github.io/posh-git)
Set-PSReadlineOption -BellStyle None
$Projects = $Env:UserProfile + "\Documents\Projects"
$Documents = $Env:UserProfile + "\Documents"
$Music = $Env:UserProfile + "\Music"
$Videos = $Env:UserProfile + "\Videos"
$Downloads = $Env:UserProfile + "\Downloads"
$Pictures = $Env:UserProfile + "\Pictures"
$Desktop = $Env:UserProfile + "\Desktop"
$ProfileDirectory = "$((Get-Item $Profile).Directory.FullName)"
$TitlePrefix = ""
function Set-TitlePrefix($Prepend) {
$Global:TitlePrefix = $Prepend
}
function Get-WorkingDirectory {
$ExecutionContext.SessionState.Path.CurrentLocation.Path
}
Set-Alias -Name Get-Path -Value Get-WorkingDirectory
function Start-NodeModule {
Invoke-Command "$(npm bin)\$Args"
}
function Get-IsAdministrator {
([System.Security.Principal.WindowsIdentity]::GetCurrent()).Groups -Match "S-1-5-32-544"
}
function Elevate([Switch]$NoExit) {
if (Get-IsAdministrator) {
Write-Host "Notice: Current session is already run as administrator." -ForegroundColor Yellow
}
Start-Process powershell -Verb runas -ArgumentList "-NoExit -Command `"cd $(Get-Path)`""
if (!$NoExit) {
Exit
}
}
function Respawn {
Start-Process powershell
if (!$NoExit) {
Exit
}
}
Set-Alias -Name Promote -Value Elevate
function Import-Script($Name) {
. "$ProfileDirectory\Scripts\$Name"
}
function Prompt {
$ExitCode = $LastExitCode
$CurrentPath = Get-Path
if ($CurrentPath.ToLower().StartsWith($Home.ToLower())) {
$CurrentPath = "~" + $CurrentPath.SubString($Home.Length)
}
if (Get-IsAdministrator) {
$Title = "Administrator: "
}
else {
$Title = ""
}
if (![String]::IsNullOrEmpty($TitlePrefix)) {
$Title += "$TitlePrefix "
}
Write-Host "$env:UserName" -NoNewline -ForegroundColor Cyan
Write-Host "@" -NoNewline -ForegroundColor Yellow
Write-Host "$(hostname) " -NoNewline
if (Test-Path ".git") {
$RemoteName = (git remote get-url origin)
Write-Host "[" -NoNewline -ForegroundColor Yellow
if ($RemoteName) {
$RemoteName = $RemoteName.Split("/")
$Title += "[$($RemoteName[-2])/$($RemoteName[-1])] "
Write-Host $RemoteName[-2] -NoNewline -ForegroundColor Cyan
Write-Host "/" -NoNewline -ForegroundColor Yellow
Write-Host $RemoteName[-1] -NoNewline
}
else {
$Title += "[NO REMOTE] "
Write-Host "NO REMOTE" -NoNewline
}
Write-Host "] " -NoNewline -ForegroundColor Yellow
$Title += "($(Get-GitBranch)) "
Write-VcsStatus
Write-Host "`n$CurrentPath " -NoNewline
}
else {
Write-Host "$CurrentPath " -NoNewline
}
if (Test-Path Variable:/PSDebugContext) {
Write-Host "PS [DBG] " -NoNewline -ForegroundColor Yellow
}
else {
Write-Host "PS " -NoNewline -ForegroundColor Yellow
}
$LastExitCode = $ExitCode
"$('>' * ($NestedPromptLevel + 1)) "
$Host.UI.RawUI.WindowTitle = $Title + $CurrentPath
}
Import-Module Posh-Git
$Global:GitPromptSettings.BeforeText = "("
$Global:GitPromptSettings.AfterText = ")"
$Global:GitPromptSettings.LocalWorkingStatusSymbol = "!!"
$Global:GitPromptSettings.EnableStashStatus = $True
$Global:GitPromptSettings.BeforeStashText = " {"
$Global:GitPromptSettings.AfterStashText = "}"
$Global:GitPromptSettings.BeforeStashForegroundColor = "Yellow"
$Global:GitPromptSettings.AfterStashForegroundColor = "Yellow"
$Global:GitPromptSettings.BranchUntrackedSymbol = "::"
$Global:GitPromptSettings.BranchGoneStatusSymbol = "~~"
$Global:GitPromptSettings.BranchIdenticalStatusToSymbol = "=="
$Global:GitPromptSettings.BranchAheadStatusSymbol = "<"
$Global:GitPromptSettings.BranchBehindStatusSymbol = ">"
$Global:GitPromptSettings.BranchBehindAndAheadStatusSymbol = "> <"
Set-Alias -Name ssh -Value New-SSHSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment