2015-05-19 22:44:32 +08:00
|
|
|
|
# Compatibility with PS major versions <= 2
|
|
|
|
|
if(!$PSScriptRoot) {
|
|
|
|
|
$PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add Cmder modules directory to the autoload path.
|
2015-03-18 23:33:55 +08:00
|
|
|
|
$CmderModulePath = Join-path $PSScriptRoot "psmodules/"
|
2014-09-17 15:55:15 +08:00
|
|
|
|
|
2015-03-18 23:33:55 +08:00
|
|
|
|
if( -not $env:PSModulePath.Contains($CmderModulePath) ){
|
|
|
|
|
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 20:22:07 +08:00
|
|
|
|
try {
|
|
|
|
|
Get-command -Name "git" -ErrorAction Stop >$null
|
|
|
|
|
Import-Module -Name "posh-git" -ErrorAction Stop >$null
|
|
|
|
|
$gitStatus = $true
|
|
|
|
|
} catch {
|
2015-05-18 05:13:23 +08:00
|
|
|
|
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
|
2015-03-25 20:22:07 +08:00
|
|
|
|
$gitStatus = $false
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-25 20:29:10 +08:00
|
|
|
|
function checkGit($Path) {
|
|
|
|
|
if (Test-Path -Path (Join-Path $Path '.git/') ) {
|
|
|
|
|
Write-VcsStatus
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
$SplitPath = split-path $path
|
|
|
|
|
if ($SplitPath) {
|
|
|
|
|
checkGit($SplitPath)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-17 15:55:15 +08:00
|
|
|
|
# Set up a Cmder prompt, adding the git prompt parts inside git repos
|
|
|
|
|
function global:prompt {
|
|
|
|
|
$realLASTEXITCODE = $LASTEXITCODE
|
2014-09-17 21:07:34 +08:00
|
|
|
|
$Host.UI.RawUI.ForegroundColor = "White"
|
2015-03-18 23:47:01 +08:00
|
|
|
|
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
|
2015-03-25 20:22:07 +08:00
|
|
|
|
if($gitStatus){
|
2015-03-25 20:29:10 +08:00
|
|
|
|
checkGit($pwd.ProviderPath)
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
2014-10-29 04:25:25 +08:00
|
|
|
|
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
|
|
|
|
|
return " "
|
2014-09-17 15:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Load special features come from posh-git
|
2015-03-25 20:22:07 +08:00
|
|
|
|
if ($gitStatus) {
|
2014-09-17 15:55:15 +08:00
|
|
|
|
Enable-GitColors
|
|
|
|
|
Start-SshAgent -Quiet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Move to the wanted location
|
|
|
|
|
if (Test-Path Env:\CMDER_START) {
|
|
|
|
|
Set-Location -Path $Env:CMDER_START
|
|
|
|
|
} elseif ($Env:CMDER_ROOT -and $Env:CMDER_ROOT.StartsWith($pwd)) {
|
|
|
|
|
Set-Location -Path $Env:USERPROFILE
|
|
|
|
|
}
|