mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 09:49:12 +08:00
65 lines
1.8 KiB
PowerShell
65 lines
1.8 KiB
PowerShell
# Compatibility with PS major versions <= 2
|
|
if(!$PSScriptRoot) {
|
|
$PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path
|
|
}
|
|
|
|
# Add Cmder modules directory to the autoload path.
|
|
$CmderModulePath = Join-path $PSScriptRoot "psmodules/"
|
|
|
|
if( -not $env:PSModulePath.Contains($CmderModulePath) ){
|
|
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
|
|
}
|
|
|
|
try {
|
|
# Check if git is on PATH, i.e. Git already installed on system
|
|
Get-command -Name "git" -ErrorAction Stop >$null
|
|
} catch {
|
|
$env:Path += ";$env:CMDER_ROOT\vendor\msysgit\bin"
|
|
}
|
|
|
|
try {
|
|
Import-Module -Name "posh-git" -ErrorAction Stop >$null
|
|
$gitStatus = $true
|
|
} catch {
|
|
Write-Warning "Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder."
|
|
$gitStatus = $false
|
|
}
|
|
|
|
function checkGit($Path) {
|
|
if (Test-Path -Path (Join-Path $Path '.git/') ) {
|
|
Write-VcsStatus
|
|
return
|
|
}
|
|
$SplitPath = split-path $path
|
|
if ($SplitPath) {
|
|
checkGit($SplitPath)
|
|
}
|
|
}
|
|
|
|
# Set up a Cmder prompt, adding the git prompt parts inside git repos
|
|
function global:prompt {
|
|
$realLASTEXITCODE = $LASTEXITCODE
|
|
$Host.UI.RawUI.ForegroundColor = "White"
|
|
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
|
|
if($gitStatus){
|
|
checkGit($pwd.ProviderPath)
|
|
}
|
|
$global:LASTEXITCODE = $realLASTEXITCODE
|
|
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
|
|
return " "
|
|
}
|
|
|
|
# Load special features come from posh-git
|
|
if ($gitStatus) {
|
|
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
|
|
}
|
|
|
|
# Enhance Path
|
|
$env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT" |