Last active
January 7, 2018 00:23
-
-
Save iainbrighton/1aaa03ad5b11107134292765fd751461 to your computer and use it in GitHub Desktop.
Default PowerShell Profile
This file contains hidden or 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 (Test-Path -Path "$env:USERPROFILE\Dropbox\PowerShell" -PathType Container) { | |
if ($Host.Name -ne 'Visual Studio Code Host') { | |
## Always default to repository root when loading in VSCode | |
Set-Location -Path "$env:USERPROFILE\Dropbox\PowerShell"; | |
} | |
if (Test-Path -Path "$env:USERPROFILE\Dropbox\PowerShell\Modules" -PathType Container) { | |
if ($env:PSModulePath -notmatch "$(($env:USERPROFILE).Replace('\','\\'))\\Dropbox\\PowerShell\\Modules") { | |
$env:PSModulePath += ";$env:USERPROFILE\Dropbox\PowerShell\Modules"; | |
} | |
} | |
} | |
else { | |
Write-Warning -Message ("Cannot locate PowerShell modules"); | |
} | |
$modules = @( | |
@{ Name = 'Posh-Git' } | |
@{ Name = 'Pester'; Alias = 'ipe'; Command = 'Invoke-Pester'; } | |
@{ Name = 'PSake'; Alias = 'ips'; Command = 'Invoke-PSake'; } | |
) | |
foreach ($module in $modules) { | |
if (Get-Module -Name $module.Name -ListAvailable) { | |
Import-Module -Name $module.Name; | |
if ($module.name -eq 'Posh-Git') { | |
## Reset the default Posh-Git dark colours | |
$global:GitPromptSettings.LocalWorkingStatusForegroundColor = [System.ConsoleColor]::Red; | |
$global:GitPromptSettings.WorkingForegroundColor = [System.ConsoleColor]::Red; | |
$global:GitPromptSettings.BeforeIndexForegroundColor = [System.ConsoleColor]::Green; | |
$global:GitPromptSettings.LocalDefaultStatusForegroundColor = [System.ConsoleColor]::Green; | |
## Register Posh-Git prompt | |
function global:prompt { | |
if (-not $?) { | |
$hasError = $true; | |
} | |
else { | |
$hasError = $false; | |
} | |
$realLASTEXITCODE = $LASTEXITCODE; | |
$providerPathSplit = New-Object -TypeName System.Collections.ArrayList -ArgumentList @(); | |
$providerPathSplit.AddRange($pwd.Drive.CurrentLocation.Split('\')); | |
if ([System.String]::IsNullOrEmpty($providerPathSplit[-1])) { | |
## Registry paths have an empty string, so remove this | |
[ref] $null = $providerPathSplit.Remove($providerPathSplit[-1]); | |
} | |
if ($providerPathSplit.Count -gt 2) { | |
$providerPathFill = '.' * ($providerPathSplit.Count -2); | |
$providerPath = '{0}\{1}\{2}\{3}' -f $pwd.Drive.Root.TrimEnd('\'), $providerPathFill, $providerPathSplit[-2], $providerPathSplit[-1]; | |
} | |
else { | |
$providerPath = $pwd.ProviderPath; | |
} | |
$prompt = '[{0}] {1}' -f (Get-History).Count, $providerPath; | |
if ($hasError) { | |
Write-Host $prompt -NoNewline -ForegroundColor Yellow; | |
} | |
else { | |
Write-Host $prompt -NoNewline; | |
} | |
Write-VcsStatus; | |
$global:LASTEXITCODE = $realLASTEXITCODE; | |
return '> '; | |
} | |
} #end if Posh-Git | |
if ($module.Alias) { | |
New-Alias -Name $module.Alias -Value $module.Command; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment