diff --git a/GitUtils.ps1 b/GitUtils.ps1 index fcdb7e133..dcadce403 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -1,12 +1,8 @@ # Inspired by Mark Embling # http://www.markembling.info/view/my-ideal-powershell-prompt-with-git-integration -. .\Utils.ps1 - function Get-GitDirectory { - Coalesce-Args ` - (Get-Item '.\.git' -Force 2>$null).FullName ` - { git rev-parse --git-dir 2>$null } + Test-LocalOrParentPath .git } function Get-GitBranch($gitDir = $(Get-GitDirectory)) { diff --git a/Utils.ps1 b/Utils.ps1 index 322fa27c8..cadda58c0 100644 --- a/Utils.ps1 +++ b/Utils.ps1 @@ -12,4 +12,16 @@ function Coalesce-Args { } $result } -Set-Alias ?? Coalesce-Args + +Remove-Item alias:/`?`? -Force +Set-Alias ?? Coalesce-Args -Force + +function Test-LocalOrParentPath($path) { + $done = $false + do { + if (Test-Path $path) { return $true } + if (Test-Path ..) { return $false } + $path = "..\$path" + } while (!$done) + return $false +} diff --git a/posh-git.psm1 b/posh-git.psm1 new file mode 100644 index 000000000..7150e4a20 --- /dev/null +++ b/posh-git.psm1 @@ -0,0 +1,13 @@ +Push-Location $psScriptRoot +. ./Utils.ps1 +. ./GitUtils.ps1 +. ./GitPrompt.ps1 +. ./GitTabExpansion.ps1 +Pop-Location + +Export-ModuleMember -Function @( + 'Write-GitStatus', + 'Get-GitStatus', + 'Enable-GitColors', + 'Get-GitDirectory', + 'GitTabExpansion') diff --git a/profile.example.ps1 b/profile.example.ps1 index 19ac78a0c..835d81ce3 100644 --- a/profile.example.ps1 +++ b/profile.example.ps1 @@ -1,13 +1,4 @@ -Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) - -# Git utils -. ./GitUtils.ps1 -. ./GitPrompt.ps1 - -# Use Git tab expansion -. ./GitTabExpansion.ps1 - -Pop-Location +Import-Module posh-git # Set up a simple prompt, adding the git prompt parts inside git repos function prompt { @@ -37,5 +28,3 @@ function TabExpansion($line, $lastWord) { } Enable-GitColors - -Pop-Location